From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C73C8386183F; Tue, 23 Feb 2021 22:39:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C73C8386183F From: "patrick.kox at commandoregel dot be" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99232] New: Exported variable in module gives error: 'lambda' was not declared in this scope Date: Tue, 23 Feb 2021 22:39:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: patrick.kox at commandoregel dot be X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Feb 2021 22:39:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99232 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 We= ert 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 func= tion template export const double lambda{1.303577269034296391257}; // Conway's constant export enum class Oddity { Even, Odd }; bool isOdd(int x) { return x % 2 !=3D 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 ; #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=3Dc++20 -c -x c++-system-header iostream 3. execute the command: g++ -fmodules-ts -Wall -Wextra -std=3Dc++20 -pedant= ic -pthread -lfmt math.cpp main.cpp //------------------------------- The full error message is: main.cpp: In function =E2=80=98int main()=E2=80=99: main.cpp:13:45: error: =E2=80=98lambda=E2=80=99 was not declared in this sc= ope 13 | std::cout << "Lambda squared: " << square(lambda) << std::endl; |=20=20=20 //------------------------------- 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)=