llvm-project/clang/test/Modules/merge-concepts.cpp
Ilya Biryukov 59179d72b2 [Sema] Merge C++20 concept definitions from different modules in same TU
Currently the C++20 concepts are only merged in `ASTReader`, i.e. when
coming from different TU. This can causes ambiguious reference errors when
trying to access the same concept that should otherwise be merged.

Please see the added test for an example.

Note that we currently use `ASTContext::isSameEntity` to check for ODR
violations. However, it will not check that concept requirements match.
The same issue holds for mering concepts from different TUs, I added a
FIXME and filed a GH issue to track this:
https://github.com/llvm/llvm-project/issues/56310

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D128921
2022-07-25 14:43:38 +02:00

65 lines
1.1 KiB
C++

// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -xc++ -std=c++20 -fmodules -fmodule-name=library \
// RUN: -emit-module %t/modules.map \
// RUN: -o %t/module.pcm
//
//
// RUN: %clang_cc1 -xc++ -std=c++20 -fmodules -fmodule-file=%t/module.pcm \
// RUN: -fmodule-map-file=%t/modules.map \
// RUN: -fsyntax-only -verify %t/use.cpp
//
//--- use.cpp
// expected-no-diagnostics
#include "concepts.h"
#include "format.h"
template <class T> void foo()
requires same_as<T, T>
{}
//--- modules.map
module "library" {
export *
module "concepts" {
export *
header "concepts.h"
}
module "format" {
export *
header "format.h"
}
}
//--- concepts.h
#ifndef SAMEAS_CONCEPTS_H_
#define SAMEAS_CONCEPTS_H_
#include "same_as.h"
#endif // SAMEAS_CONCEPTS_H
//--- same_as.h
#ifndef SAME_AS_H
#define SAME_AS_H
template <class T, class U>
concept same_as = __is_same(T, U);
#endif // SAME_AS_H
//--- format.h
#ifndef FORMAT_H
#define FORMAT_H
#include "concepts.h"
#include "same_as.h"
template <class T> void foo()
requires same_as<T, int>
{}
#endif // FORMAT_H