PR c++/38647
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 31 Dec 2008 11:46:18 +0000 (11:46 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 31 Dec 2008 11:46:18 +0000 (11:46 +0000)
* parser.c (cp_parser_primary_expression) <case RID_FUNCTION_NAME>:
Return error_mark_node if cp_parser_non_integral_constant_expression
returns true.

* g++.dg/template/function1.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@142978 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/function1.C [new file with mode: 0644]

index 6f34380..e6cb289 100644 (file)
@@ -1,5 +1,10 @@
 2008-12-31  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/38647
+       * parser.c (cp_parser_primary_expression) <case RID_FUNCTION_NAME>:
+       Return error_mark_node if cp_parser_non_integral_constant_expression
+       returns true.
+
        PR c++/38640
        * semantics.c (finish_decltype_type): Handle TEMPLATE_PARM_INDEX.
 
index e21aa8e..545d3dd 100644 (file)
@@ -3308,16 +3308,39 @@ cp_parser_primary_expression (cp_parser *parser,
        case RID_FUNCTION_NAME:
        case RID_PRETTY_FUNCTION_NAME:
        case RID_C99_FUNCTION_NAME:
-         /* The symbols __FUNCTION__, __PRETTY_FUNCTION__, and
-            __func__ are the names of variables -- but they are
-            treated specially.  Therefore, they are handled here,
-            rather than relying on the generic id-expression logic
-            below.  Grammatically, these names are id-expressions.
+         {
+           const char *name;
 
-            Consume the token.  */
-         token = cp_lexer_consume_token (parser->lexer);
-         /* Look up the name.  */
-         return finish_fname (token->u.value);
+           /* The symbols __FUNCTION__, __PRETTY_FUNCTION__, and
+              __func__ are the names of variables -- but they are
+              treated specially.  Therefore, they are handled here,
+              rather than relying on the generic id-expression logic
+              below.  Grammatically, these names are id-expressions.
+
+              Consume the token.  */
+           token = cp_lexer_consume_token (parser->lexer);
+
+           switch (token->keyword)
+             {
+             case RID_FUNCTION_NAME:
+               name = "%<__FUNCTION__%>";
+               break;
+             case RID_PRETTY_FUNCTION_NAME:
+               name = "%<__PRETTY_FUNCTION__%>";
+               break;
+             case RID_C99_FUNCTION_NAME:
+               name = "%<__func__%>";
+               break;
+             default:
+               gcc_unreachable ();
+             }
+
+           if (cp_parser_non_integral_constant_expression (parser, name))
+             return error_mark_node;
+
+           /* Look up the name.  */
+           return finish_fname (token->u.value);
+         }
 
        case RID_VA_ARG:
          {
index 6b66b92..9a8aaa1 100644 (file)
@@ -1,5 +1,8 @@
 2008-12-31  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/38647
+       * g++.dg/template/function1.C: New test.
+
        PR c++/38640
        * g++.dg/cpp0x/decltype15.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/template/function1.C b/gcc/testsuite/g++.dg/template/function1.C
new file mode 100644 (file)
index 0000000..1097c5b
--- /dev/null
@@ -0,0 +1,27 @@
+// PR c++/38647
+// { dg-do compile }
+
+template<const char *, int> struct A {};
+const char func[] = "abc";
+template<int N> struct A<func, N> {};  // { dg-error "cannot appear|is invalid" }
+
+char a1[1];
+A<a1, 0> a;
+
+template<const char *, int> struct B {};
+template<int N> struct B<__FUNCTION__, N> {};  // { dg-error "cannot appear|is invalid" }
+
+char b1[1];
+B<b1, 0> b;
+
+template<const char *, int> struct C {};
+template<int N> struct C<__PRETTY_FUNCTION__, N> {};   // { dg-error "cannot appear|is invalid" }
+
+char c1[1];
+C<c1, 0> c;
+
+template<const char *, int> struct D {};
+template<int N> struct D<__func__, N> {};      // { dg-error "cannot appear|is invalid" }
+
+char d1[1];
+D<d1, 0> d;