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++/84494] New: Invalid constexpr with default assignment operator


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

            Bug ID: 84494
           Summary: Invalid constexpr with default assignment operator
           Product: gcc
           Version: 7.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pigman46 at gmail dot com
  Target Milestone: ---

$ cat test.cpp
#include <iostream>

struct X
{
        constexpr X() = default;
        constexpr X(int x) : m_value(x) {}
        constexpr X& operator=(const X &o) = default;

        int m_value {};
};

int main ()
{
        constexpr int x = (X() = X(10)).m_value;
        std::cout << x << std::endl;
        std::cout << (X() = X(10)).m_value << std::endl;
}




g++ -v -save-temps -o test test.cpp -Wall -Wextra
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin
--enable-initfini-array --with-isl --enable-libmpx
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686
--build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180130 (Red Hat 7.3.1-2) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'test' '-Wall' '-Wextra'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -E -quiet -v -D_GNU_SOURCE
test.cpp -mtune=generic -march=x86-64 -Wall -Wextra -fpch-preprocess -o test.ii
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-redhat-linux/7/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-redhat-linux/7/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7

/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/x86_64-redhat-linux
 /usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/backward
 /usr/lib/gcc/x86_64-redhat-linux/7/include
 /usr/local/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'test' '-Wall' '-Wextra'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -fpreprocessed test.ii -quiet
-dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -Wall -Wextra
-version -o test.s
GNU C++14 (GCC) version 7.3.1 20180130 (Red Hat 7.3.1-2) (x86_64-redhat-linux)
        compiled by GNU C version 7.3.1 20180130 (Red Hat 7.3.1-2), GMP version
6.1.2, MPFR version 3.1.5, MPC version 1.0.2, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (GCC) version 7.3.1 20180130 (Red Hat 7.3.1-2) (x86_64-redhat-linux)
        compiled by GNU C version 7.3.1 20180130 (Red Hat 7.3.1-2), GMP version
6.1.2, MPFR version 3.1.5, MPC version 1.0.2, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 41dde25dbc62f10f0477c356c02ccf33
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'test' '-Wall' '-Wextra'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o test.o test.s
GNU assembler version 2.29 (x86_64-redhat-linux) using BFD version version
2.29-6.fc27
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/7/:/usr/libexec/gcc/x86_64-redhat-linux/7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/7/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/7/:/usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'test' '-Wall' '-Wextra'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/7/collect2 -plugin
/usr/libexec/gcc/x86_64-redhat-linux/7/liblto_plugin.so
-plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
-plugin-opt=-fresolution=test.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id
--no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -o test
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-redhat-linux/7/crtbegin.o
-L/usr/lib/gcc/x86_64-redhat-linux/7
-L/usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64 -L/lib/../lib64
-L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/7/../../.. test.o
-lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/x86_64-redhat-linux/7/crtend.o
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../lib64/crtn.o
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'test' '-Wall' '-Wextra'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'




$ ./test 
0
10




If using "= default" on a constexpr copy/move assignment operator, an constexpr
evaluation involving this operator produces an invalid result. In this case,
m_value contains 0 instead of 10.

Its usage in a non-constexpr context yields the expected value.

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