Bug 69700 - [C++14] constexpr incorrectly implies const
Summary: [C++14] constexpr incorrectly implies const
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.2.0
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2016-02-05 22:38 UTC by Michael Price (Synopsys)
Modified: 2021-07-23 02:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
preprocessed source (144 bytes, text/plain)
2016-02-05 22:38 UTC, Michael Price (Synopsys)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Price (Synopsys) 2016-02-05 22:38:54 UTC
Created attachment 37602 [details]
preprocessed source

The following code (derived from the subject of CWG DR 1683) should be ill-formed in C++14:

  struct A {
      constexpr A() {}
      constexpr operator int() { return 1; }
  };

  template <int> struct X {};

  constexpr A a;
  X<a> x;


GCC compiles it as if it were C++11, under which it is well-formed. The output below is from 5.2.0, but the behavior 4.9.0 through 5.3.0 seemed consistent.

  $ g++ -v -save-temps -c -std=c++14 constexpr-vs-const.cpp
  Using built-in specs.
  COLLECT_GCC=/opt/pkg/gcc-5.2.0/bin/g++
  Target: x86_64-unknown-linux-gnu
  Configured with: ../gcc-5.2.0/configure --prefix=/opt/pkg/gcc-5.2.0 --program-suffix=-5.2.0 --enable-languages=c,c++
  Thread model: posix
  gcc version 5.2.0 (GCC)
  COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-std=c++14' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
   /opt/pkg/gcc-5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/cc1plus -E -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE constexpr-vs-const.cpp -mtune=generic -march=x86-64 -std=c++14 -fpch-preprocess -o constexpr-vs-const.ii
  ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
  ignoring nonexistent directory "/opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../x86_64-unknown-linux-gnu/include"
  #include "..." search starts here:
  #include <...> search starts here:
   /opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../include/c++/5.2.0
   /opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../include/c++/5.2.0/x86_64-unknown-linux-gnu
   /opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../include/c++/5.2.0/backward
   /opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include
   /usr/local/include
   /opt/pkg/gcc-5.2.0/include
   /opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include-fixed
   /usr/include/x86_64-linux-gnu
   /usr/include
  End of search list.
  COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-std=c++14' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
   /opt/pkg/gcc-5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/cc1plus -fpreprocessed constexpr-vs-const.ii -quiet -dumpbase constexpr-vs-const.cpp -mtune=generic -march=x86-64 -auxbase constexpr-vs-const -std=c++14 -version -o constexpr-vs-const.s
  GNU C++14 (GCC) version 5.2.0 (x86_64-unknown-linux-gnu)
          compiled by GNU C version 5.2.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
  GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
  GNU C++14 (GCC) version 5.2.0 (x86_64-unknown-linux-gnu)
          compiled by GNU C version 5.2.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
  GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
  Compiler executable checksum: d48b14d3a677b3306bfa594605d7fb25
  COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-std=c++14' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
   as -v --64 -o constexpr-vs-const.o constexpr-vs-const.s
  GNU assembler version 2.22 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.22
  COMPILER_PATH=/opt/pkg/gcc-5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/:/opt/pkg/gcc-5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/:/opt/pkg/gcc-5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/:/opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/:/opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/
  LIBRARY_PATH=/opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/:/opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/opt/pkg/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../:/lib/:/usr/lib/
  COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-std=c++14' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
  $
Comment 1 Daniel Krügler 2016-02-06 22:26:02 UTC
The same problem also exists in the current gcc 6.0 trunk (tested using gcc 6.0.0 20160131 (experimental))
Comment 2 Andrew Pinski 2021-07-23 02:49:46 UTC
Fixed in GCC 7.