Skip to content

[Clang] Clang rejects anonymous struct with generic lambda while GCC/MSVC accept #152244

@Xniao

Description

@Xniao

Clang rejects following C++ code containing generic lambda in anonymous struct's member function, while both GCC and MSVC accept the same code. This affects all forms of generic lambdas like auto&x, auto... x.

Program

typedef struct {
    void foo() {
        auto f = [](auto&& x) {};
        f(f);
    }
} Test;

Clang Output

<source>:1:15: error: anonymous non-C-compatible type given name for linkage purposes by typedef declaration after its linkage was computed; add a tag name here to establish linkage prior to definition
    1 | typedef struct {
      |               ^
      |                Test
<source>:2:5: note: type is not C-compatible due to this member declaration
    2 |     void foo() {
      |     ^~~~~~~~~~~~
    3 |         auto f = [](auto&& x) {};
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~
    4 |         f(f);
      |         ~~~~~
    5 |     }
      |     ~
<source>:6:3: note: type is given name 'Test' for linkage purposes by this typedef declaration
    6 | } Test;
      |   ^
1 error generated.
Compiler returned: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:edgDoes the clang frontend diverge from edg compiler on this issuediverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issuegenerated by fuzzerinvalidResolved as invalid, i.e. not a buglambdaC++11 lambda expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions