Bug 91746 - Bogus error due to a type and variable with the same name
Summary: Bogus error due to a type and variable with the same name
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-11 22:34 UTC by Dávid Bolvanský
Modified: 2019-09-11 22:44 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dávid Bolvanský 2019-09-11 22:34:29 UTC
GCC fails to compile:

struct pixel {
    int x;
    int y;
};

struct master {
    pixel pixel;
};


<source>:9:11: error: declaration of 'pixel master::pixel' changes meaning of 'pixel' [-fpermissive]

    9 |     pixel pixel;

      |           ^~~~~

<source>:3:8: note: 'pixel' declared here as 'struct pixel'

    3 | struct pixel {

      |        ^

Clang, ICC, MSVC - compiles it just fine.
Comment 1 Andrew Pinski 2019-09-11 22:41:29 UTC
No GCC is correct. this is invalid C++ though there is no diagnostic required by the C++ standard.   GCC checks for this case while the other two compilers you citied don't.
Comment 2 Andrew Pinski 2019-09-11 22:44:41 UTC
Just for refernce of the C++ standard wording:
[basic.scope.class] paragraph 2:

"A name N used in a class S shall refer to the same declaration in its context and when re-evaluated in the completed scope of S. No diagnostic is required for a violation of this rule."

NOTE the "No dianostic is required" part.  So even though it is invalid to do this, compilers don't need to check for volations.  If you want clang/MSVC to detect the violation of this rule, please file a bug with them.