https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102545
Bug ID: 102545
Summary: inlining constexpr is required yet it should not be.
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: e9leyland at outlook dot com
Target Milestone: ---
I module file rev.cpp there is the following,
module;
export import <concepts>;
export import <limits>;
export module rev;
namespace rev {
export inline constexpr auto FAV_TEST_VAL = u8'9';
}
In the consumer file, main.cpp there is this,
import rev;
import <iostream>;
int
main(int, char**)
{
auto TEST_VAL = rev::FAV_TEST_VAL;
std::cout << std::hex << int(TEST_VAL) << std::endl;
}
The makefile has,
$ cat Makefile
.PHONY: default
default: main ;
gcmcache:
g++ -fmodules-ts -std=c++20 -x c++-system-header concepts
g++ -fmodules-ts -std=c++20 -x c++-system-header limits
g++ -fmodules-ts -std=c++20 -x c++-system-header iostream
rev.o: rev.cpp
g++ -c -std=c++20 -fmodules-ts rev.cpp
main: main.cpp rev.o
g++ -fmodules-ts -std=c++20 -o main main.cpp rev.o
clean:
rm rev.o main.exe rm -rf gcm.cache
The constexpr must be given the inline specifier to work, because if it is not
there the following error occurs.
$ make
g++ -c -std=c++20 -fmodules-ts rev.cpp
g++ -fmodules-ts -std=c++20 -o main main.cpp rev.o
main.cpp: In function ‘int main(int, char**)’:
main.cpp:7:26: error: ‘FAV_TEST_VAL’ is not a member of ‘rev’
7 | auto TEST_VAL = rev::FAV_TEST_VAL;
| ^~~~~~~~~~~~
make: *** [Makefile:13: main] Error 1
Shouldn't the constexpr be sufficient to inline the function from the standard?
In comparison to VS2022 the inline is not required, nor should it be.