This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/83020] New: ('17) Class template constructor call skipped with no error when substitution fails in default argument
- From: "oremanj at mit dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 16 Nov 2017 15:46:18 +0000
- Subject: [Bug c++/83020] New: ('17) Class template constructor call skipped with no error when substitution fails in default argument
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83020
Bug ID: 83020
Summary: ('17) Class template constructor call skipped with no
error when substitution fails in default argument
Product: gcc
Version: 7.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: oremanj at mit dot edu
Target Milestone: ---
The below C++ program is ill-formed, but gcc 7.1 and 7.2 accept it in C++17
mode, and emit code that simply doesn't call the constructor of Whoops at all.
This is reproducible if the constructor is defined out-of-line as well; there's
no reference to Whoops in the generated assembly. In C++14 mode or with gcc
6.3, the error is correctly diagnosed.
$ cat t.cc
struct NoDefault {
int val = 1234;
NoDefault(int v) : val(v) {}
};
template <class T>
struct Whoops {
const char *str;
T obj;
Whoops(const char *s, T v = T()) : str(s), obj(v) {}
};
const char *test() {
return Whoops<NoDefault>("hi").str;
}
$ g++-7 -O3 -std=c++17 -Wall -c t.cc && objdump -d t.o
t.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z4testv>:
0: 31 c0 xor %eax,%eax
2: c3 retq
$ g++-7 -O0 -std=c++17 -Wall -c t.cc && objdump -d t.o
t.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_Z4testv>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 5d pop %rbp
5: c3 retq
$ g++-7 -v
Using built-in specs.
COLLECT_GCC=g++-7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian
7.2.0-12+hrtdeb8u1' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-7
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=gcc4-compatible --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib
--with-target-system-zlib --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i586 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu --disable-initfini-array
Thread model: posix
gcc version 7.2.1 20171025 (Debian 7.2.0-12)