https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122310
Bug ID: 122310
Summary: Compilation error when including before importing
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: d7d1cd at mail dot ru
Target Milestone: ---
The header file contains a Foo type with a static lambda inside:
#pragma once
struct Foo {
constexpr static inline auto do_nothing = [](auto && ...){};
using TNothing = decltype(do_nothing);
};
This header file is included in the module's GMF, and the Foo type is exported
in the module:
module;
#include "header.h"
export module M;
export using ::Foo;
In the implementation file, the header file is first included, then the module
is imported. Next, a container with the Foo type is created:
#include <vector>
#include "header.h"
import M;
int main() {
std::vector<Foo> v;
}
This results in the following error:
confused by earlier errors, bailing out
Here's a replica on godbolt: https://godbolt.org/z/q5zsjb871
This example is synthetic. No one would include both the header and import the
module. However, this can happen if the header is contained within another
header and transitively appears before the module import.
If you move the lambda definition out of the Foo type, the error disappears:
https://godbolt.org/z/9h6seeEb4