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++/86354] New: Address comparison not a constant expression


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

            Bug ID: 86354
           Summary: Address comparison not a constant expression
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pdimov at gmail dot com
  Target Milestone: ---

The following code:

```
struct X {};

struct Y: X {};
struct Z: X {};

extern Y y;
extern Z z;

constexpr X const& x1() { return y; }
constexpr X const& x2() { return z; }

static_assert( &x1() != &x2() );
```

yields (with g++ 7.3 and 8.1)

```
testbed2017.cpp:12:1: error: non-constant condition for static assertion
 static_assert( &x1() != &x2() );
 ^~~~~~~~~~~~~
testbed2017.cpp:12:22: error: '(((const X*)(& y)) != ((const X*)(& z)))' is not
a constant expression
 static_assert( &x1() != &x2() );
                ~~~~~~^~~~~~~~
```

but other compilers accept it.

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