public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "patrick.kox at commandoregel dot be" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-99232-4@http.gcc.gnu.org/bugzilla/> (raw) 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)
next reply other threads:[~2021-02-23 22:39 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-23 22:39 patrick.kox at commandoregel dot be [this message] 2023-08-15 19:00 ` [Bug c++/99232] " yagreg7 at gmail dot com 2023-11-24 13:55 ` cvs-commit at gcc dot gnu.org 2024-02-11 13:42 ` nshead at gcc dot gnu.org 2024-02-11 14:07 ` nshead at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-99232-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).