re PR c++/46930 ([C++0x] ICE with static constexpr data member)
authorJason Merrill <jason@redhat.com>
Wed, 15 Dec 2010 00:35:17 +0000 (19:35 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 15 Dec 2010 00:35:17 +0000 (19:35 -0500)
PR c++/46930
* decl.c (grokdeclarator): Reject uninitialized constexpr
static data member.

From-SVN: r167834

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-decl.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C
gcc/testsuite/g++.dg/cpp0x/constexpr-static5.C

index d9d8f04b5b300eea72c51ca8b5c79a1ea5e9228c..142dd533ac725ca20d775751a1ce5afbcc6d3064 100644 (file)
@@ -1,3 +1,9 @@
+2010-12-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/46930
+       * decl.c (grokdeclarator): Reject uninitialized constexpr
+       static data member.
+
 2010-12-14  Nathan Froyd  <froydnj@codesourcery.com>
 
        PR c++/45330
index 1be0f979b1e87737751de4ffccedc2f6fe2f7c9a..f9331bc147643a5a2255af9cd9383bf5f7ff2dec 100644 (file)
@@ -9763,6 +9763,13 @@ grokdeclarator (const cp_declarator *declarator,
 
                if (thread_p)
                  DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
+
+               if (constexpr_p && !initialized)
+                 {
+                   error ("constexpr static data member %qD must have an "
+                          "initializer", decl);
+                   constexpr_p = false;
+                 }
              }
            else
              {
index f3210512f89d3e40f2ae36490e89fddf7f81a10f..60e48b39d0cabc1d7b64f8adbc33f5bc5e827b2c 100644 (file)
@@ -1,3 +1,10 @@
+2010-12-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/46930
+       * g++.dg/cpp0x/constexpr-decl.C: New.
+       * g++.dg/cpp0x/constexpr-ex1.C: Fix.
+       * g++.dg/cpp0x/constexpr-static5.C: Fix.
+
 2010-12-14  Jan Hubicka  <jh@suse.cz>
 
        PR lto/46940
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-decl.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-decl.C
new file mode 100644 (file)
index 0000000..0a3fcb6
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/46930
+// { dg-options -std=c++0x }
+
+struct S {
+  static constexpr int size;   // { dg-error "must have an initializer" }
+  // { dg-error "previous declaration" "" { target *-*-* } 5 }
+};
+
+const int limit = 2 * S::size;
+constexpr int S::size = 256;   // { dg-error "" }
index c7757f4759889abe652e6de27cbef3b81a9b9ae6..6b090a03f0f4c196c57e54d9f322eb626e5a5203 100644 (file)
@@ -16,9 +16,9 @@ struct S {
     constexpr int twice();
     constexpr int t();         // { dg-message "used but never defined" }
 private:
-    static constexpr int val;  // constexpr variable
+    static constexpr int val = 7;  // constexpr variable
 };
-constexpr int S::val = 7;
+
 constexpr int S::twice() { return val + val; }
 constexpr S s = { };
 int x1 = s.twice();     // ok
index cb553a25fe8b48d78f8c8b12764881480a99378c..a401cc0b890125f9db560008ec417df2a203c40b 100644 (file)
@@ -3,10 +3,10 @@
 template <class T>
 struct A
 {
-  constexpr static T t;
+  constexpr static T t = T();  // { dg-error "literal" }
 };
 template <class T>
-constexpr T A<T>::t = T();     // { dg-error "not literal" }
+constexpr T A<T>::t;
 
 struct B
 {