https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103749

            Bug ID: 103749
           Summary: Misleading error message on template/non-template
                    conflict
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drepper.fsp+rhbz at gmail dot com
  Target Milestone: ---

This problem isn't new in the trunk version, it exists in all versions I
tested.

This is the code in question:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct foo {
  template<typename>
  friend struct bar;
};

struct bar {
  int baz;
};

bar var;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is obviously buggy, the actual definition of 'bar' is not a template
class.   This is exactly what clang tell me:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ clang++ -c u.cc
u.cc:6:8: error: redefinition of 'bar' as different kind of symbol
struct bar {
       ^
u.cc:3:17: note: previous definition is here
  friend struct bar;
                ^
u.cc:10:1: error: unknown type name 'bar'
bar var;
^
2 errors generated.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

With g++ the error messages are misleading and it also generates a lot more
unnecessary text:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ g++ -c u.cc
u.cc:6:8: error: template argument required for ‘struct bar’
    6 | struct bar {
      |        ^~~
u.cc:10:5: error: class template argument deduction failed:
   10 | bar var;
      |     ^~~
u.cc:10:5: error: no matching function for call to ‘bar()’
u.cc:3:17: note: candidate: ‘template<class> bar()-> bar<
<template-parameter-1-1> >’
    3 |   friend struct bar;
      |                 ^~~
u.cc:3:17: note:   template argument deduction/substitution failed:
u.cc:10:5: note:   couldn’t deduce template parameter
‘<template-parameter-1-1>’
   10 | bar var;
      |     ^~~
u.cc:3:17: note: candidate: ‘template<class> bar(bar< <template-parameter-1-1>
>)-> bar< <template-parameter-1-1> >’
    3 |   friend struct bar;
      |                 ^~~
u.cc:3:17: note:   template argument deduction/substitution failed:
u.cc:10:5: note:   candidate expects 1 argument, 0 provided
   10 | bar var;
      |     ^~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to