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++/85944] New: Address of member variable of temporary not considered constexpr at global scope


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

            Bug ID: 85944
           Summary: Address of member variable of temporary not considered
                    constexpr at global scope
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david at doublewise dot net
  Target Milestone: ---

When compiling the following code in C++11, C++14, C++17, or C++2a with 8.1 or
trunk (not tested with earlier versions):


struct S {
    int x = 0;
};

constexpr bool f(S const & s) {
    return &s.x;
}

constexpr auto x = f(S{});




gcc gives this error message:


<source>:6:12: error: '((&<anonymous>.S::x) != 0)' is not a constant expression

  return &s.x;

            ^

Compiler returned: 1





Putting the declaration of `x` inside a function rather than at global scope
fixes the error, as does creating a constexpr variable to store the result of
`S{}` and then passing that to `f`.

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