https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100881
Bug ID: 100881
Summary: [c++ modules][possible bug?] default arguments break
when the default argument's type isn't explicitly
included/exported
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: evanc.github at gmail dot com
Target Milestone: ---
Created attachment 50911
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50911&action=edit
Preprocessed output of foo.cc
GCC Version / steps to reproduce:
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/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++,fortran,objc,obj-c++,ada,go,d,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=/builddir/build/BUILD/gcc-11.1.1-20210428/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --enable-cet --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.1 20210428 (Red Hat 11.1.1-1) (GCC)
$ cat foo.cc
module;
#include <source_location>
export module foo;
export void log(const std::source_location& loc =
std::source_location::current()) {
//
}
$ cat main.cc
import foo;
int main() {
log();
}
$ g++ -fmodules-ts -std=c++20 -c foo.cc -o foo.o
$ g++ -fmodules-ts -std=c++20 main.cc foo.o
main.cc: In function ‘int main()’:
main.cc:4:8: error: ‘source_location’ is not a member of ‘std’
4 | log();
| ~~~^~
main.cc:1:1: note: ‘std::source_location’ is defined in header
‘<source_location>’; did you forget to ‘#include <source_location>’?
+++ |+#include <source_location>
1 | import foo;
main.cc:4:8: note: evaluating ‘__builtin_source_location’
4 | log();
| ~~~^~
In file included from foo.cc:2,
of module foo, imported at main.cc:1:
main.cc:4:8: in ‘constexpr’ expansion of
‘std::source_location@foo::current(0)’
/usr/include/c++/11/source_location:54:23: error: cast from ‘const void*’ is
not allowed
54 | __ret._M_impl = static_cast <const __impl*>(__p);
|
=====================================================================================
Apologies if this isn't actually a bug, but it seemed to be.
This error disappears when <source_location> is included in main.cc or `export
import <source_location` is present in foo.cc (along with a compiled header
unit for <source_location>).