public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/55003 (wrong error with auto template static data member)
@ 2013-02-15  1:17 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2013-02-15  1:17 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 279 bytes --]

Normally we defer instantiation of the initializer of a static data 
member of a template class until it is actually needed.  If we need it 
for deducing the type of the variable, we can go ahead and instantiate 
it at that point.

Tested x86_64-pc-linux-gnu, applying to trunk.

[-- Attachment #2: 55003.patch --]
[-- Type: text/x-patch, Size: 1319 bytes --]

commit fe74d7110cbaf9ccf153e2950eee04fe0907a988
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Feb 14 12:39:19 2013 -0500

    	PR c++/55003
    	* decl.c (cp_finish_decl): Force instantiation of an
    	auto static data member.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index eb6c490..3d63389 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6111,6 +6111,15 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
       tree d_init;
       if (init == NULL_TREE)
 	{
+	  if (DECL_TEMPLATE_INSTANTIATION (decl)
+	      && !DECL_TEMPLATE_INSTANTIATED (decl))
+	    {
+	      /* init is null because we're deferring instantiating the
+		 initializer until we need it.  Well, we need it now.  */
+	      instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
+	      return;
+	    }
+
 	  error ("declaration of %q#D has no initializer", decl);
 	  TREE_TYPE (decl) = error_mark_node;
 	  return;
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto37.C b/gcc/testsuite/g++.dg/cpp0x/auto37.C
new file mode 100644
index 0000000..f4b2904
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto37.C
@@ -0,0 +1,14 @@
+// PR c++/55003
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+struct A {
+  static const auto t
+    = (typename T::type)42;
+};
+
+struct X {
+  typedef int type;
+};
+
+A<X> a;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-02-15  1:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-15  1:17 C++ PATCH for c++/55003 (wrong error with auto template static data member) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).