This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++0x constexpr PATCH #5: two more small tweaks
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 31 Oct 2010 21:47:54 -0400
- Subject: C++0x constexpr PATCH #5: two more small tweaks
These small changes improve diagnostics: first by avoiding an ICE on a
non-static data member declared constexpr, second by suggesting
-std=c++0x when constexpr is encountered as an invalid type name.
Tested x86_64-pc-linux-gnu, applied to trunk.
commit 2dfb67f2a9915a1ae200ac4e4fc784fec725f912
Author: Jason Merrill <jason@redhat.com>
Date: Thu Oct 28 09:33:14 2010 -0400
* decl.c (grokdeclarator): Don't ICE on constexpr non-static data
member.
* parser.c (cp_parser_diagnose_invalid_type_name): Give helpful
message about constexpr without -std=c++0x.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d73d109..dfe37d9 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9652,8 +9652,11 @@ grokdeclarator (const cp_declarator *declarator,
else
{
if (constexpr_p)
- error ("non-static data member %qE declared %<constexpr%>",
- unqualified_id);
+ {
+ error ("non-static data member %qE declared %<constexpr%>",
+ unqualified_id);
+ constexpr_p = false;
+ }
decl = build_decl (input_location,
FIELD_DECL, unqualified_id, type);
DECL_NONADDRESSABLE_P (decl) = bitfield;
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 851e9c4..33d8561 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2698,8 +2698,11 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser,
template <typename T> struct B : public A<T> { X x; };
The user should have said "typename A<T>::X". */
- if (processing_template_decl && current_class_type
- && TYPE_BINFO (current_class_type))
+ if (cxx_dialect < cxx0x && id == ridpointers[(int)RID_CONSTEXPR])
+ inform (location, "C++0x %<constexpr%> only available with "
+ "-std=c++0x or -std=gnu++0x");
+ else if (processing_template_decl && current_class_type
+ && TYPE_BINFO (current_class_type))
{
tree b;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-98.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-98.C
new file mode 100644
index 0000000..4ae3944
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-98.C
@@ -0,0 +1,4 @@
+// { dg-options "-std=c++98" }
+
+constexpr int i = 42; // { dg-message "std=c\\+\\+0x" }
+// { dg-error "constexpr" "" { target *-*-* } 3 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-nonstatic.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-nonstatic.C
new file mode 100644
index 0000000..3951fbd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-nonstatic.C
@@ -0,0 +1,6 @@
+// { dg-options -std=c++0x }
+
+struct A
+{
+ constexpr int i; // { dg-error "" }
+};