diff mbox

[C++] PR 58878

Message ID 526A8DFA.5090301@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Oct. 25, 2013, 3:27 p.m. UTC
Hi,

here the issue is that we fail to detect shadowing declarations in 
inline member function templates. The reason is the following check in 
check_template_shadow:

    if (decl == olddecl
-      || TEMPLATE_PARMS_FOR_INLINE (current_template_parms))
+      || (DECL_TEMPLATE_PARM_P (decl)
+      && TEMPLATE_PARMS_FOR_INLINE (current_template_parms)))
      return true;

which, to avoid duplicate error messages involving template parameters 
(see g++.old-deja/g++.benjamin/tem0[34].C) ends up skipping VAR_DECLs 
etc too.

Tested x86_64-linux.

Thanks,
Paolo.

/////////////////////////
/cp
2013-10-25  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58878
	* pt.c (check_template_shadow): Don't skip declarations in inline
	member templates.

/testsuite
2013-10-25  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58878
	* g++.dg/template/pr58878.C: New.

Comments

Jason Merrill Oct. 25, 2013, 3:36 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 204056)
+++ cp/pt.c	(working copy)
@@ -3511,7 +3511,8 @@  check_template_shadow (tree decl)
      name inside a class.  We check TPFI to avoid duplicate errors for
      inline member templates.  */
   if (decl == olddecl
-      || TEMPLATE_PARMS_FOR_INLINE (current_template_parms))
+      || (DECL_TEMPLATE_PARM_P (decl)
+	  && TEMPLATE_PARMS_FOR_INLINE (current_template_parms)))
     return true;
 
   error ("declaration of %q+#D", decl);
Index: testsuite/g++.dg/template/pr58878.C
===================================================================
--- testsuite/g++.dg/template/pr58878.C	(revision 0)
+++ testsuite/g++.dg/template/pr58878.C	(working copy)
@@ -0,0 +1,62 @@ 
+// PR c++/58878
+
+// Template-members of non-template class
+struct A
+{
+    template <typename t>    // { dg-error "shadows" }
+        void f()
+        {
+            int t = 1;       // { dg-error "declaration" }
+        }
+
+    template <typename t>
+        void g();
+};
+
+template <typename t>        // { dg-error "shadows" }
+void A::g()
+{
+    int t = 2;               // { dg-error "declaration" }
+}
+
+// (Non-template) Members of template class
+template <typename t>        // { dg-error "shadows" }
+struct B
+{
+    void f()
+    {
+        int t = 3;           // { dg-error "declaration" }
+    }
+
+    void g();
+};
+
+template <typename t>        // { dg-error "shadows" }
+void B<t>::g()
+{
+    int t = 4;               // { dg-error "declaration" }
+}
+
+
+// Template members of template class
+template <typename t>        // { dg-error "shadows" }
+struct C
+{
+    template <typename s>    // { dg-error "shadows" }
+    void f()
+    {
+        int t = 5;           // { dg-error "declaration" }
+        int s = 6;           // { dg-error "declaration" }
+    }
+
+    template <typename s>
+    void g();
+};
+
+template <typename t>        // { dg-error "shadows" }
+template <typename s>        // { dg-error "shadows" }
+void C<t>::g()
+{
+    int t = 7;               // { dg-error "declaration" }
+    int s = 8;               // { dg-error "declaration" }
+}