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++/71896] New: Constexpr function with pointer to member parameter doesn't return constexpr value


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

            Bug ID: 71896
           Summary: Constexpr function with pointer to member parameter
                    doesn't return constexpr value
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: raphael.kargon at gmail dot com
  Target Milestone: ---

Created attachment 38913
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38913&action=edit
Preprocessed source that produces this error.

The following code fails to compile in gcc 6.1.0, but compiles successfully in
clang:
```
#include <type_traits>

struct Foo {
  int x;
};

constexpr bool compare(int Foo::*t) { return t == &Foo::x; }

int main(int, char **) {
  // GCC will fail here, "(&Foo::x == 0) is not a constant expression"
  constexpr bool b = compare(&Foo::x);
  return b ? 0 : 1;
}
```

The compiler output is:
constexpr-test.cpp: In function 'int main(int, char**)':
constexpr-test.cpp:11:29:   in constexpr expansion of 'compare(&Foo::x)'
constexpr-test.cpp:7:48: error: '(&Foo::x == 0)' is not a constant expression
 constexpr bool compare(int Foo::*t) { return t == &Foo::x; }

The commands used to compile are:
gcc-6 --std=c++14 --save-temps -Wall -Wextra constexpr-test.cpp -o
constexpr-test
clang --std=c++14 --save-temps -Wall -Wextra constexpr-test.cpp -o
constexpr-test 

Preprocessed source is attached. 

Output of "gcc-6 --version":

Using built-in specs.
COLLECT_GCC=gcc-6
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/6.1.0/libexec/gcc/x86_64-apple-darwin15.5.0/6.1.0/lto-wrapper
Target: x86_64-apple-darwin15.5.0
Configured with: ../configure --build=x86_64-apple-darwin15.5.0
--prefix=/usr/local/Cellar/gcc/6.1.0
--libdir=/usr/local/Cellar/gcc/6.1.0/lib/gcc/6
--enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-6
--with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr
--with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl
--with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking
--enable-checking=release --enable-lto --with-build-config=bootstrap-debug
--disable-werror --with-pkgversion='Homebrew gcc 6.1.0'
--with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin
--disable-nls --enable-multilib
Thread model: posix
gcc version 6.1.0 (Homebrew gcc 6.1.0)

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