Index: lib/Sema/SemaExprCXX.cpp =================================================================== --- lib/Sema/SemaExprCXX.cpp +++ lib/Sema/SemaExprCXX.cpp @@ -2658,6 +2658,8 @@ Context, GlobalCtx, SourceLocation(), SourceLocation(), Name, FnType, /*TInfo=*/nullptr, SC_None, false, true); Alloc->setImplicit(); + // Global allocation functions should always be visible. + Alloc->setHidden(false); // Implicit sized deallocation functions always have default visibility. Alloc->addAttr( Index: test/Modules/Inputs/local-submodule-globaldelete/a.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/a.h @@ -0,0 +1,6 @@ +#ifndef A_H +#define A_H +class A { + virtual ~A(){}; +}; +#endif Index: test/Modules/Inputs/local-submodule-globaldelete/b.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/b.h @@ -0,0 +1,6 @@ +#ifndef B_H +#define B_H +class B { + virtual ~B(){}; +}; +#endif Index: test/Modules/Inputs/local-submodule-globaldelete/c.h =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/c.h @@ -0,0 +1,6 @@ +#ifndef C_H +#define C_H +class C { + virtual ~C(){}; +}; +#endif Index: test/Modules/Inputs/local-submodule-globaldelete/module.modulemap =================================================================== --- /dev/null +++ test/Modules/Inputs/local-submodule-globaldelete/module.modulemap @@ -0,0 +1,7 @@ +module M { + module a { header "a.h" export * } + module b { header "b.h" export * } +} +module Other { + module c { header "c.h" export * } +} Index: test/Modules/local-submodule-globaldelete.cpp =================================================================== --- /dev/null +++ test/Modules/local-submodule-globaldelete.cpp @@ -0,0 +1,23 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cp -r %S/Inputs/local-submodule-globaldelete %t/local-submodule-globaldelete +// RUN: cd %t +// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -verify -fmodules-cache-path=%t -fimplicit-module-maps -I local-submodule-globaldelete %s -H + +// expected-no-diagnostics + +// This tests that the global delete operator is not by accident assigned +// to a submodule in local-submodule-visibility mode. This could happen +// when the operator is created on demand when we discover a virtual destructor +// inside a module. + +// Build a module with submodules that each need the global delete operator. +#include "a.h" +// Build another module with another global delete operator to check that +// we didn't introduced ambiguity in the lookup. +#include "c.h" + +// Require a lookup of the global delete operator. +class T { + virtual ~T() {} +};