public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99232] New: Exported variable in module gives error: 'lambda' was not declared in this scope
@ 2021-02-23 22:39 patrick.kox at commandoregel dot be
  2023-08-15 19:00 ` [Bug c++/99232] " yagreg7 at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: patrick.kox at commandoregel dot be @ 2021-02-23 22:39 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-11 14:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-23 22:39 [Bug c++/99232] New: Exported variable in module gives error: 'lambda' was not declared in this scope patrick.kox at commandoregel dot be
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

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).