1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 2c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith 3c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith// A constexpr specifier used in an object declaration declares the object as 4c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith// const. 5c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithconstexpr int a = 0; 6c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithextern const int a; 7c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith 87098cbd601ad915aed22d4b5850da99359f25bf3Richard Smithint i; // expected-note 2{{here}} 9c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithconstexpr int *b = &i; 10c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithextern int *const b; 11c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith 12c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithconstexpr int &c = i; 13c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithextern int &c; 14c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith 15c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithconstexpr int (*d)(int) = 0; 16c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithextern int (*const d)(int); 17c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith 18c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith// A variable declaration which uses the constexpr specifier shall have an 19c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith// initializer and shall be initialized by a constant expression. 2066f85713bd0d22f867efa8e9fb0037befdd6b151Richard Smithconstexpr int ni1; // expected-error {{default initialization of an object of const type 'const int'}} 2186c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr struct C { C(); } ni2; // expected-error {{cannot have non-literal type 'const struct C'}} expected-note 3{{has no constexpr constructors}} 2266f85713bd0d22f867efa8e9fb0037befdd6b151Richard Smithconstexpr double &ni3; // expected-error {{declaration of reference variable 'ni3' requires an initializer}} 23c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith 247098cbd601ad915aed22d4b5850da99359f25bf3Richard Smithconstexpr int nc1 = i; // expected-error {{constexpr variable 'nc1' must be initialized by a constant expression}} expected-note {{read of non-const variable 'i' is not allowed in a constant expression}} 2586c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr C nc2 = C(); // expected-error {{cannot have non-literal type 'const C'}} 26099e7f647ccda915513f2b2ec53352dc756082d3Richard Smithint &f(); // expected-note {{declared here}} 27099e7f647ccda915513f2b2ec53352dc756082d3Richard Smithconstexpr int &nc3 = f(); // expected-error {{constexpr variable 'nc3' must be initialized by a constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}} 287098cbd601ad915aed22d4b5850da99359f25bf3Richard Smithconstexpr int nc4(i); // expected-error {{constexpr variable 'nc4' must be initialized by a constant expression}} expected-note {{read of non-const variable 'i' is not allowed in a constant expression}} 2986c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr C nc5((C())); // expected-error {{cannot have non-literal type 'const C'}} 30099e7f647ccda915513f2b2ec53352dc756082d3Richard Smithint &f(); // expected-note {{here}} 31099e7f647ccda915513f2b2ec53352dc756082d3Richard Smithconstexpr int &nc6(f()); // expected-error {{constexpr variable 'nc6' must be initialized by a constant expression}} expected-note {{non-constexpr function 'f'}} 32c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith 33c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithstruct pixel { 34c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith int x, y; 35c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smith}; 36c6d990a767150b02337de1136fdb55ccf349f4d1Richard Smithconstexpr pixel ur = { 1294, 1024 }; // ok 3766f85713bd0d22f867efa8e9fb0037befdd6b151Richard Smithconstexpr pixel origin; // expected-error {{default initialization of an object of const type 'const pixel' requires a user-provided default constructor}} 38