https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99232
Bug ID: 99232 Summary: Exported variable in module gives error: 'lambda' was not declared in this scope Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: patrick.kox at commandoregel dot be Target Milestone: --- When compiling Ex11-01 from the book "Beginning C++20" by Horton and Van Weert there is an error message that the exported variable (const double) was not declared. here is the code: //math.cpp export module math; export auto square(const auto& x) { return x * x; } // An abbreviated function template export const double lambda{1.303577269034296391257}; // Conway's constant export enum class Oddity { Even, Odd }; bool isOdd(int x) { return x % 2 != 0; } // Module-local function (not exported) export auto getOddity(int x) { return isOdd(x) ? Oddity::Odd : Oddity::Even; } //------------------------------- // main.cpp // Consuming your own module import <iostream>; #define FMT_HEADER_ONLY #include "fmt/format.h" import math; int main() { std::cout << "Lambda squared: " << square(lambda) << std::endl; int number; std::cout << "\nPlease enter an odd number: "; std::cin >> number; std::cout << std::endl; switch (getOddity(number)) { using enum Oddity; case Odd: std::cout << "Well done! And remember: you have to be odd to be number one!"; break; case Even: fmt::print("Odd, {} seems to be even?", number); break; } std::cout << std::endl; } //------------------------------- To compile I do the following: 1. copy iostream into my source directory 2. execute the command: g++ -Wall -Wextra -fmodules-ts -std=c++20 -c -x c++-system-header iostream 3. execute the command: g++ -fmodules-ts -Wall -Wextra -std=c++20 -pedantic -pthread -lfmt math.cpp main.cpp //------------------------------- The full error message is: main.cpp: In function ‘int main()’: main.cpp:13:45: error: ‘lambda’ was not declared in this scope 13 | std::cout << "Lambda squared: " << square(lambda) << std::endl; | //------------------------------- If I move the declaration of the lambda variable to the main.cpp sourcefile the code does compile, so the other exports seem to work correctly. the version of GCC is: g++ (GCC) 11.0.0 20210214 (experimental)