* decl.c (cp_make_fname_decl): Set DECL_THIS_STATIC at toplevel.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 10 Feb 2011 16:30:20 +0000 (16:30 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 10 Feb 2011 16:30:20 +0000 (16:30 +0000)
* semantics.c (finish_fname): Only return the name if we're in
a function.

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

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/regress/template-function1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/function1.C

index 20b0d4b..c3f780a 100644 (file)
@@ -1,5 +1,9 @@
 2011-02-09  Jason Merrill  <jason@redhat.com>
 
+       * decl.c (cp_make_fname_decl): Set DECL_THIS_STATIC at toplevel.
+       * semantics.c (finish_fname): Only return the name if we're in
+       a function.
+
        * decl.c (build_enumerator): Don't perform integral promotions on
        non-integral constants.
 
index 866069d..663ca8f 100644 (file)
@@ -3706,7 +3706,10 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
                      LOOKUP_ONLYCONVERTING);
     }
   else
-    pushdecl_top_level_and_finish (decl, init);
+    {
+      DECL_THIS_STATIC (decl) = true;
+      pushdecl_top_level_and_finish (decl, init);
+    }
 
   return decl;
 }
index 7c06cc3..58a59ee 100644 (file)
@@ -2324,7 +2324,7 @@ finish_fname (tree id)
   tree decl;
 
   decl = fname_decl (input_location, C_RID_CODE (id), id);
-  if (processing_template_decl)
+  if (processing_template_decl && current_function_decl)
     decl = DECL_NAME (decl);
   return decl;
 }
index dc522e3..a43f34c 100644 (file)
@@ -1,5 +1,8 @@
 2011-02-09  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/template/function1.C: Adjust for C++0x mode.
+       * g++.dg/cpp0x/regress/template-function1.C: Copy it.
+
        * g++.dg/ext/label10.C: Adjust for C++0x mode.
        * g++.dg/cpp0x/regress/ext-label10.C: Copy it.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/template-function1.C b/gcc/testsuite/g++.dg/cpp0x/regress/template-function1.C
new file mode 100644 (file)
index 0000000..ec686ee
--- /dev/null
@@ -0,0 +1,28 @@
+// PR c++/38647
+// { dg-do compile }
+// { dg-options "-std=c++0x" }
+
+template<const char *, int> struct A {};
+const char func[] = "abc";
+template<int N> struct A<func, N> {};  // { dg-error "cannot appear|is invalid|not a valid" }
+
+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|is not a valid" }
+
+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|is not a valid" }
+
+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|is not a valid|function scope" }
+
+char d1[1];
+D<d1, 0> d;
index 1097c5b..3f82d53 100644 (file)
@@ -3,25 +3,25 @@
 
 template<const char *, int> struct A {};
 const char func[] = "abc";
-template<int N> struct A<func, N> {};  // { dg-error "cannot appear|is invalid" }
+template<int N> struct A<func, N> {};  // { dg-error "cannot appear|is invalid|not a valid" }
 
 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" }
+template<int N> struct B<__FUNCTION__, N> {};  // { dg-error "cannot appear|is invalid|is not a valid" }
 
 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" }
+template<int N> struct C<__PRETTY_FUNCTION__, N> {};   // { dg-error "cannot appear|is invalid|is not a valid" }
 
 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" }
+template<int N> struct D<__func__, N> {};      // { dg-error "cannot appear|is invalid|is not a valid|function scope" }
 
 char d1[1];
 D<d1, 0> d;