13 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,narrowing %s2// RUN: %clang_cc1 -fsyntax-only -Wno-c++11-narrowing-const-reference -verify %s3 4struct A { A(const unsigned &x) {} };5 6void 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