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

            Bug ID: 103566
           Summary: confusing error message for typedefs with initializers
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

On this code GCC says:

    typedef int foo = 42;
    error: typedef 'foo' is initialized (use 'decltype' instead)

I believe this error message is quite confusing. It wasn't clear to me how
'decltype' could help here. After a bit of git-blaming I found the original
commit that added this message:

author  Zack Weinberg <z...@gcc.gnu.org>
Sat, 19 Oct 2002 03:14:11 +0000 (03:14 +0000)
commit  4a7510cb22da4809d18e3bb3fc453cf671d6926a

    c-decl.c, decl.c (start_decl): Point users of the old initialized- typedef
extension at __typeof__.

-       error ("typedef `%D' is initialized", decl);
+       error ("typedef `%D' is initialized (use __typeof__ instead)", decl);

Unfortunately the commit wasn't accompanied by a testcase, but I assume in the
past there was some GCC-specific extension "initialized typedef" that worked
like decltype/typeof.

I believe that the error message although beneficial in the past is confusing
for users today. I would like to suggest removing "(use 'decltype' instead)"
text.

Reply via email to