From: Jason Merrill Date: Mon, 1 Nov 2010 02:04:30 +0000 (-0400) Subject: decl.c (grokdeclarator): Don't ICE on constexpr non-static data member. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=202be748c9997016f1b08c98291db4b7b9b02a5f;p=gcc.git decl.c (grokdeclarator): Don't ICE on constexpr non-static data member. * 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. From-SVN: r166122 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8df704f2bd3..1a8837cff94 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2010-10-31 Jason Merrill + + * parser.c (cp_parser_diagnose_invalid_type_name): Give helpful + message about constexpr without -std=c++0x. + + * decl.c (grokdeclarator): Don't ICE on constexpr non-static data + member. + 2010-10-30 Nathan Froyd * class.c (layout_vtable_decl): Call build_array_of_n_type. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d73d109af81..dfe37d92a32 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 %", - unqualified_id); + { + error ("non-static data member %qE declared %", + 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 851e9c4c36d..33d8561603b 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 struct B : public A { X x; }; The user should have said "typename A::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 % 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 00000000000..4ae3944c34d --- /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 00000000000..3951fbdb15c --- /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 "" } +};