Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC][C++20][Modules] Relax ODR check in unnamed modules #111160

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ class alignas(8) Decl {
/// Whether this declaration comes from a named module.
bool isInNamedModule() const;

/// Whether this declaration comes from a header unit.
bool isFromHeaderUnit() const;

/// Return true if this declaration has an attribute which acts as
/// definition of the entity, such as 'alias' or 'ifunc'.
bool hasDefiningAttr() const;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Serialization/ASTReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ class BitsUnpacker {

inline bool shouldSkipCheckingODR(const Decl *D) {
return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
D->isFromGlobalModule();
(D->isFromGlobalModule() || D->isFromHeaderUnit());
}

} // namespace clang
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/DeclBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,10 @@ bool Decl::isInNamedModule() const {
return getOwningModule() && getOwningModule()->isNamedModule();
}

bool Decl::isFromHeaderUnit() const {
return getOwningModule() && getOwningModule()->isHeaderUnit();
}

static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }

Expand Down
40 changes: 40 additions & 0 deletions clang/test/Headers/header-unit-common-cmp-cat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: rm -fR %t
// RUN: split-file %s %t
// RUN: cd %t
// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf -I. -emit-header-unit -xc++-user-header bz1.h
// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf -I. -emit-header-unit -xc++-user-header bz2.h
// RUN: %clang_cc1 -verify -std=c++20 -fskip-odr-check-in-gmf -I. -emit-header-unit -xc++-user-header -fmodule-file=bz1.pcm -fmodule-file=bz2.pcm bz.cpp

//--- compare
namespace std {
namespace __detail {

template<typename _Tp>
inline constexpr unsigned __cmp_cat_id = 1;

template<typename... _Ts>
constexpr auto __common_cmp_cat() {
(__cmp_cat_id<_Ts> | ...);
}

} // namespace __detail
} // namespace std

//--- bz0.h
template <class T>
int operator|(T, T);

//--- bz1.h
#include "bz0.h"
#include <compare>
// expected-no-diagnostics

//--- bz2.h
#include <compare>
// expected-no-diagnostics

//--- bz.cpp
#include <compare>

import "bz1.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
import "bz2.h"; // expected-warning {{the implementation of header units is in an experimental phase}}
Loading