Skip to content

[C++20] [Modules] Merging of lambda types  #57222

Closed
@ilya-biryukov

Description

@ilya-biryukov

I believe this code should not produce the static assertion failure:

//--- lambda.h
#pragma once

inline auto cmp = [](auto l, auto r) {
  return l < r;
};
//--- A.cppm
module;
#include "lambda.h"

export module A;
export auto c1 = cmp;
export using ::cmp;
//--- B.cppm
module;
#include "lambda.h"

export module B;
export auto c2 = cmp;
export using ::cmp;
//--- use.cppm
module;

export module use;

import A;
import B;

static_assert(__is_same(decltype(c1), decltype(c2))); // should succeed.
auto x = cmp; // cmp must not be ambiguous,

// Build with:
// clang++ -std=c++20 --precompile -o A.pcm A.cppm
// clang++ -std=c++20 --precompile -o B.pcm B.cppm
// clang++ -std=c++20 -fprebuilt-module-path=. use.cppm

As the lambda meets all requirements specified in basic.def.odr and cmp is declared inline. I.e. this should be no different from explicit class declaration from lambda.

However, the static assertion currently fails and the use of 'cmp' produces an "ambiguous reference" error.

Metadata

Metadata

Assignees

Labels

c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"clang:modulesC++20 modules and Clang Header ModulesconfirmedVerified by a second party

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions