[Bug c++/79493] New: Bad diagnostic when referring to inner type that does not exist

me at haldean dot org gcc-bugzilla@gcc.gnu.org
Mon Feb 13 17:42:00 GMT 2017


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

            Bug ID: 79493
           Summary: Bad diagnostic when referring to inner type that does
                    not exist
           Product: gcc
           Version: 6.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: me at haldean dot org
  Target Milestone: ---

Created attachment 40729
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40729&action=edit
C++ source that exercises the poor diagnostic

Hi all,

The following code snippet (this is the same as the contents of the attached
file):

    struct A { int x; };

    struct B {
        void *DoThing(A::nonexistent param);
    };

Emits the following compiler diagnostics, when compiling with "g++
BadTypeDiagnostic.cpp"

BadTypeDiagnostic.cpp:4:11: error: expected ‘;’ at end of member declaration
     void *DoThing(A::nonexistent param);
           ^
BadTypeDiagnostic.cpp:4:34: error: expected ‘)’ before ‘param’
     void *DoThing(A::nonexistent param);
                                  ^

This is not particularly helpful to the programmer; the error here is in the
type chosen for param, not the syntax of the declaration of DoThing. In this
trivial example, the error is obvious, but when there is a minor typo in your
attempt at mimicking the misspelling of an inner class in a third-party
library, this is enough to pull your hair out for hours ;)

I found this with "g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609", but
testing on godbolt.org (https://godbolt.org/g/10zL5i) shows that the diagnostic
is the same for GCC 6.3. For reference, clang's diagnostic here is "no type
named 'nonexistent' in 'A'", which does point at the cause of the error.


More information about the Gcc-bugs mailing list