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++/82193] New: incorrectly rejects int x; struct { decltype(x) x; } f = {x};


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

            Bug ID: 82193
           Summary: incorrectly rejects int x; struct { decltype(x) x; } f
                    = {x};
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marc.mutz at kdab dot com
  Target Milestone: ---

This code:

  void fun() {
    constexpr int x = 42;

    constexpr struct {
        decltype(x) x;

        constexpr auto operator()(int a) const { return a * x; }
    } f = {x};
    static_assert(f(0) == 0);
    static_assert(f(2) == 2*42);
  }

(trying to show how a compiler might expand a lambda [x](int a){return a*x;}),
fails to compile on all GCCs I tested, incl. trunk as installed on godbold,
with the following incomprehensible error message:

6 : <source>:6:21: error: declaration of 'const int fun()::<unnamed struct>::x'
[-fpermissive]
         decltype(x) x;
                     ^
3 : <source>:3:19: error: changes meaning of 'x' from 'constexpr const int x'
[-fpermissive]
     constexpr int x = 42;
                   ^


Clang 4 and MSVC 2017 both compile this code just fine:
https://godbolt.org/g/4L6ULo

The problem is not the constexpr. I only added those to be able to execute the
function call operator without having to run the executable.

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