public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103749] New: Misleading error message on template/non-template conflict
@ 2021-12-16 15:41 drepper.fsp+rhbz at gmail dot com
  2021-12-16 15:47 ` [Bug c++/103749] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2021-12-16 15:41 UTC (permalink / raw)
  To: gcc-bugs

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;
      |     ^~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-17 18:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-16 15:41 [Bug c++/103749] New: Misleading error message on template/non-template conflict drepper.fsp+rhbz at gmail dot com
2021-12-16 15:47 ` [Bug c++/103749] " mpolacek at gcc dot gnu.org
2021-12-16 16:16 ` mpolacek at gcc dot gnu.org
2021-12-16 19:46 ` mpolacek at gcc dot gnu.org
2021-12-16 19:59 ` mpolacek at gcc dot gnu.org
2021-12-16 20:16 ` drepper.fsp+rhbz at gmail dot com
2021-12-17 18:08 ` cvs-commit at gcc dot gnu.org
2021-12-17 18:17 ` mpolacek at gcc dot gnu.org

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).