xref: /llvm-project/clang/test/SemaCXX/GH63151.cpp (revision dd85c6cce4fc60fa4850770d66f783300a700f3a)
1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,narrowing %s
2 // RUN: %clang_cc1 -fsyntax-only -Wno-c++11-narrowing-const-reference -verify %s
3 
AA4 struct A { A(const unsigned &x) {} };
5 
foo(int p)6 void foo(int p) {
7   A a { -1 }; // narrowing-error {{constant expression evaluates to -1 which cannot be narrowed to type 'unsigned int'}}
8   A b { 0 };
9   A c { p }; // narrowing-error {{non-constant-expression cannot be narrowed from type 'int' to 'unsigned int' in initializer list}}
10   A d { 0.5 }; // narrowing-error {{type 'double' cannot be narrowed to 'unsigned int' in initializer list}}
11                // expected-warning@-1 {{implicit conversion from 'double' to 'unsigned int' changes value from 0.5 to 0}}
12 }
13