llvm-capstone/clang/test/Modules/merge-concepts.cpp
Ilya Biryukov 42f87bb62d [Sema] Return primary merged decl as canonical for concepts
Otherwise we get invalid results for ODR checks. See changed test for an
example: despite the fact that we merge the first concept, its **uses**
were considered different by `Profile`, leading to redefinition errors.

After this change, canonical decl for a concept can come from a
different module and may not be visible. This behavior looks suspicious,
but does not break any tests. We might want to add a mechanism to make
the canonical concept declaration visible if we find code that relies on
this invariant.

Additionally make sure we always merge with the canonical declaration to
avoid chains of merged concepts being reported as redefinitions. An
example was added to the test.

Also change the order of includes in the test. Importing a moduralized
header before its textual part causes the include guard macro to be
exported and the corresponding `#include` becomes a no-op.

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D130585
2022-07-27 12:31:20 +02:00

85 lines
1.4 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 "compare" {
export *
header "compare.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_impl = __is_same(T, U);
template <class T, class U>
concept same_as = same_as_impl<T, U> && same_as_impl<U, T>;
#endif // SAME_AS_H
//--- compare.h
#ifndef COMPARE_H
#define COMPARE_H
#include "same_as.h"
#include "concepts.h"
template <class T> void foo()
requires same_as<T, int>
{}
#endif // COMPARE_H
//--- format.h
#ifndef FORMAT_H
#define FORMAT_H
#include "same_as.h"
#include "concepts.h"
template <class T> void bar()
requires same_as<T, int>
{}
#endif // FORMAT_H