From: Richard Smith Date: Mon, 9 Mar 2015 23:46:50 +0000 (+0000) Subject: [modules] Don't assert if the same header is named as both a public and a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e32a61193f8faa43b949892f0dc2d6baf447a143;p=clang [modules] Don't assert if the same header is named as both a public and a private header within the same module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231725 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index 0bb98568b2..b4fe98488b 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -222,15 +222,24 @@ static bool violatesPrivateInclude(Module *RequestingModule, // Check for consistency between the module header role // as obtained from the lookup and as obtained from the module. // This check is not cheap, so enable it only for debugging. - bool IsPrivate = false; - SmallVectorImpl *HeaderList[] = - {&RequestedModule->Headers[Module::HK_Private], - &RequestedModule->Headers[Module::HK_PrivateTextual]}; - for (auto *Hdrs : HeaderList) - IsPrivate |= - std::find_if(Hdrs->begin(), Hdrs->end(), [&](const Module::Header &H) { - return H.Entry == IncFileEnt; - }) != Hdrs->end(); + auto IsInHeaderList = [&](std::initializer_list*> HeaderList) -> bool { + for (auto *Hs : HeaderList) { + if (std::find_if(Hs->begin(), Hs->end(), [&](const Module::Header &H) { + return H.Entry == IncFileEnt; + }) != Hs->end()) + return true; + } + return false; + }; + // If a header is both public and private, then it's available as a public + // header and that's OK. + // FIXME: Should we reject this when parsing the module map? + bool IsPrivate = + IsInHeaderList({&RequestedModule->Headers[Module::HK_Private], + &RequestedModule->Headers[Module::HK_PrivateTextual]}) && + !IsInHeaderList({&RequestedModule->Headers[Module::HK_Normal], + &RequestedModule->Headers[Module::HK_Textual]}); assert(IsPrivate == IsPrivateRole && "inconsistent headers and roles"); #endif return IsPrivateRole && diff --git a/test/Modules/Inputs/empty.h b/test/Modules/Inputs/empty.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/Modules/public-private.modulemap b/test/Modules/public-private.modulemap new file mode 100644 index 0000000000..b07d161665 --- /dev/null +++ b/test/Modules/public-private.modulemap @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fmodules -fmodule-map-file=%s -I%S -include "Inputs/empty.h" /dev/null +module Blah { + header "Inputs/empty.h" + private header "Inputs/empty.h" +}