From 752ada870d7bc5759a80abde286c77e95ef77fb6 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 17 Nov 2015 23:32:01 +0000 Subject: [modules] When a #include is mapped to a module import and appears somewhere other than the top level, we issue an error. This breaks a fair amount of C++ code wrapping C libraries, where the C library is #included within a namespace / extern "C" combination, because the C library (probably) includes C++ standard library headers which may be within modules. Without modules, this setup is harmless if (and *only* if) the corresponding standard library module was already included outside the namespace, so downgrade the error to a default-error extension in that case, so that it can be selectively disabled for such misbehaving libraries. llvm-svn: 253398 --- clang/test/Modules/auto-module-import.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'clang/test') diff --git a/clang/test/Modules/auto-module-import.m b/clang/test/Modules/auto-module-import.m index 76441fcfedc..9a34c92eab2 100644 --- a/clang/test/Modules/auto-module-import.m +++ b/clang/test/Modules/auto-module-import.m @@ -1,6 +1,7 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify -DERRORS // RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs %s -verify +// RUN: %clang_cc1 -Wauto-import -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -F %S/Inputs -xobjective-c++ %s -verify // // Test both with and without the declarations that refer to unimported // entities. For error recovery, those cases implicitly trigger an import. @@ -85,5 +86,16 @@ int getNotInModule() { void includeNotAtTopLevel() { // expected-note {{function 'includeNotAtTopLevel' begins here}} #include // expected-warning {{treating #include as an import}} \ - expected-error {{import of module 'NoUmbrella.A' appears within function 'includeNotAtTopLevel'}} + expected-error {{redundant #include of module 'NoUmbrella.A' appears within function 'includeNotAtTopLevel'}} } + +#ifdef __cplusplus +namespace NS { // expected-note {{begins here}} +#include // expected-warning {{treating #include as an import}} \ + expected-error {{redundant #include of module 'NoUmbrella.A' appears within namespace 'NS'}} +} +extern "C" { // expected-note {{begins here}} +#include // expected-warning {{treating #include as an import}} \ + expected-error {{import of C++ module 'NoUmbrella.A' appears within extern "C"}} +} +#endif -- cgit v1.2.3