Skip to content

Commit

Permalink
[Modules] Don't prevent @import from ObjectiveC
Browse files Browse the repository at this point in the history
Previously we forbiden the users to import named modules from clang header
modules. However, due to an oversight, the @import form of Objective C
got involved. This is not want and we fix that in this patch.
  • Loading branch information
ChuanqiXu9 committed Dec 28, 2023
1 parent 3081bac commit c2c840b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,8 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
if (!Mod)
return true;

if (!Mod->isInterfaceOrPartition() && !ModuleName.empty()) {
if (!Mod->isInterfaceOrPartition() && !ModuleName.empty() &&
!getLangOpts().ObjC) {
Diag(ImportLoc, diag::err_module_import_non_interface_nor_parition)
<< ModuleName;
return true;
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Modules/pr64755.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fmodule-file=a0=%t/a0.pcm -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fprebuilt-module-path=%t -verify -fsyntax-only

// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%t -fmodule-name=a0 -x objective-c++ -emit-module %t/module.modulemap -o %t/a0.pcm
// RUN: %clang_cc1 -std=c++20 -x objective-c++ %t/use_obj.cpp -fmodule-file=%t/a0.pcm -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -x objective-c++ %t/use_obj.cpp -fmodule-file=a0=%t/a0.pcm -verify -fsyntax-only
// RUN: %clang_cc1 -std=c++20 -x objective-c++ %t/use_obj.cpp -fprebuilt-module-path=%t -verify -fsyntax-only

//--- module.modulemap
module a0 { header "a0.h" export * }

Expand All @@ -15,3 +20,7 @@ void a0() {}

//--- use.cpp
import a0; // expected-error {{import of module 'a0' imported non C++20 importable modules}}

//--- use_obj.cpp
// expected-no-diagnostics
@import a0;

0 comments on commit c2c840b

Please sign in to comment.