brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 4b54221 Raw
59 lines · cpp
1// RUN: %clang_cc1 -Wno-uninitialized -fsyntax-only -verify -std=c++11 -Wno-error=static-float-init %s 2 3int vs = 0; // expected-note {{declared here}}4 5class C {6public:7  struct NestedC {8    NestedC(int);9  };10 11  int i = 0;12  static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}13  static const NestedC ci = 0; // expected-error {{static data member of type 'const NestedC' must be initialized out of line}}14  static const int nci = vs; // expected-error {{in-class initializer for static data member is not a constant expression}} \15                             // expected-note {{read of non-const variable 'vs' is not allowed in a constant expression}}16  static const int vi = 0;17  static const volatile int cvi = 0; // expected-error {{static const volatile data member must be initialized out of line}}18};19 20namespace rdar8367341 {21  float foo(); // expected-note 2 {{here}}22 23  struct A {24    static const float x = 5.0f; // expected-warning {{requires 'constexpr'}} expected-note {{add 'constexpr'}}25    static const float y = foo(); // expected-warning {{requires 'constexpr'}} expected-note {{add 'constexpr'}} \26                                  // expected-error {{in-class initializer for static data member is not a constant expression}} \27                                  // expected-note {{non-constexpr function 'foo' cannot be used in a constant expression}}28    static constexpr float x2 = 5.0f;29    static constexpr float y2 = foo(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr function 'foo'}}30  };31}32 33 34namespace Foo {35  // Regression test -- forward declaration of Foo should not cause error about36  // nonstatic data member.37  class Foo;38  class Foo {39    int x;40    int y = x;41  };42}43 44// Instantiating another default member initializer while parsing one should45// not cause us to mess up the 'this' override.46template<typename> struct DefaultMemberTemplate { int n = 0; };47class DefaultMemberInitSelf {48  DefaultMemberTemplate<int> t = {};49  int *p = &t.n;50};51 52namespace composed_templates {53  // Regression test -- obtaining the type from composed templates should not54  // require out-of-line definition.55  template <typename T> struct Zero { static const typename T::type value = 0; };56  struct Integer { using type = int; };57  template struct Zero<Integer>;58}59