Hi,

today I noticed the below while I was putting together another batch of minor diagnostic fixes. The error + error to error + inform change seems rather straightforward to me and as usual adds clarity to the diagnostic outputs (all the front-ends I have at hand either do something similar or do not output the inform part at all). However, there is a subtler issue. For example the first pair of errors we currently output for constexpr-specialization.C is the following (I'm removing original code and carets for clarity):

constexpr-specialization.C:7:26: error: redeclaration ‘constexpr int foo(T) [with T = int]’ differs in ‘constexpr’

constexpr-specialization.C:6:16: error: from previous declaration ‘constexpr int foo(T) [with T = int]’

see? The pretty printing of the previous declaration is very misleading because it has constexpr in it! The same happens for the dual type of error. Now, I suppose we should investigate that a bit more, I don't think it's the first time we notice this, but I'm wondering if for the time being we could just apply something like the below, which just does away with the prettyprinting for the inform, just uses "previous declaration here", something that in any case we already do in a number of places...

Thanks,
Paolo.

/////////////////////

Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 237443)
+++ cp/decl.c   (working copy)
@@ -1278,8 +1278,11 @@ validate_constexpr_redeclaration (tree old_decl, t
          && DECL_TEMPLATE_SPECIALIZATION (new_decl))
        return true;
 
-      error ("redeclaration %q+D differs in %<constexpr%>", new_decl);
-      error ("from previous declaration %q+D", old_decl);
+      error_at (DECL_SOURCE_LOCATION (new_decl),
+               "redeclaration %qD differs in %<constexpr%> "
+               "from previous declaration", new_decl);
+      inform (DECL_SOURCE_LOCATION (old_decl),
+             "previous declaration here");
       return false;
     }
   return true;
Index: testsuite/g++.dg/cpp0x/constexpr-specialization.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-specialization.C   (revision 237443)
+++ testsuite/g++.dg/cpp0x/constexpr-specialization.C   (working copy)
@@ -3,10 +3,10 @@
 
 template<typename T> constexpr int foo(T);
 template<> int foo(int);
-template<> int foo(int);            // { dg-error "previous" }
+template<> int foo(int);            // { dg-message "previous" }
 template<> constexpr int foo(int);  // { dg-error "redeclaration" }
 
 template<typename T> int bar(T);
 template<> constexpr int bar(int);
-template<> constexpr int bar(int);  // { dg-error "previous" }
+template<> constexpr int bar(int);  // { dg-message "previous" }
 template<> int bar(int);            // { dg-error "redeclaration" }

Reply via email to