This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/61457] New: Inaccurately refusing non-ODR usage of type with no linkage


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

            Bug ID: 61457
           Summary: Inaccurately refusing non-ODR usage of type with no
                    linkage
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: filip.roseen at gmail dot com

Created attachment 32912
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=32912&action=edit
testcase.cpp

enum { X };

struct A { static constexpr auto val = X; };

int main () {
  int x = A::val;
}


-------------------------

`gcc` is inaccurately rejecting `testcase.cpp` with the following diagnostic:


 > testcase.cpp:3:34: error: âconstexpr const<anonymous enum> A::valâ, declared
 > using anonymous type, is used but never defined [-fpermissive]
 > struct A { static constexpr auto val = X; };
 >                                  ^

-------------------------

A detailed answer was provided by me at
http://stackoverflow.com/a/24019645/1090079

It is stated that an unnamed enum has no linkage in [basic.link]p8, but we must
also remember the following which is also stated in [basic.link]p8:

  >  A type without linkage shall not be used as the type of a variable
  >  or function with external linkage unless:
  >    - the entity has C language linkage (7.5), or
  >    - the entity is declared within an unnamed namespace (7.3.1), or
  >    - the entity is not odr-used (3.2) or is defined in the same translation
         unit

----------------------------

`clang` correctly accepts the snippet.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]