Hi,
I split out two - rather straightforward IMHO - changes from the largish
patch I posted a few days ago: this one improves the accuracy of some
error messages produced by grokfndecl.
Tested x86_64-linux.
Thanks,
Paolo.
//////////////////////
/cp
2013-03-25 Paolo Carlini <paolo.carl...@oracle.com>
* decl.c (grokfndecl): Handle separately <inline> and <constexpr>
error messages.
/testsuite
2013-03-25 Paolo Carlini <paolo.carl...@oracle.com>
* g++.dg/cpp0x/constexpr-friend-2.C: New.
* g++.dg/cpp0x/constexpr-main.C: Likewise.
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 197053)
+++ cp/decl.c (working copy)
@@ -7426,13 +7426,16 @@ grokfndecl (tree ctype,
return NULL_TREE;
}
+ if (inlinep & 1)
+ error ("%<inline%> is not allowed in declaration of friend "
+ "template specialization %qD",
+ decl);
+ if (inlinep & 2)
+ error ("%<constexpr%> is not allowed in declaration of friend "
+ "template specialization %qD",
+ decl);
if (inlinep)
- {
- error ("%<inline%> is not allowed in declaration of friend "
- "template specialization %qD",
- decl);
- return NULL_TREE;
- }
+ return NULL_TREE;
}
}
@@ -7471,8 +7474,10 @@ grokfndecl (tree ctype,
{
if (PROCESSING_REAL_TEMPLATE_DECL_P())
error ("cannot declare %<::main%> to be a template");
- if (inlinep)
+ if (inlinep & 1)
error ("cannot declare %<::main%> to be inline");
+ if (inlinep & 2)
+ error ("cannot declare %<::main%> to be constexpr");
if (!publicp)
error ("cannot declare %<::main%> to be static");
inlinep = 0;
Index: testsuite/g++.dg/cpp0x/constexpr-friend-2.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-friend-2.C (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-friend-2.C (working copy)
@@ -0,0 +1,7 @@
+// { dg-do compile { target c++11 } }
+
+template<typename T> void f(T);
+
+template <class T> class A {
+ friend constexpr void f<>(int); // { dg-error "'constexpr' is not allowed" }
+};
Index: testsuite/g++.dg/cpp0x/constexpr-main.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-main.C (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-main.C (working copy)
@@ -0,0 +1,3 @@
+// { dg-do compile { target c++11 } }
+
+constexpr int main (); // { dg-error "constexpr" }