diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -763,7 +763,7 @@ } DeclContext *DC = ND->getDeclContext(); - if (!DC->isExternCContext()) { + if (getLangOpts().CPlusPlus && !DC->isExternCContext()) { Diag(Loc, diag::err_pragma_alloc_text_c_linkage); return; } diff --git a/clang/test/Sema/pragma-ms-alloc-text.c b/clang/test/Sema/pragma-ms-alloc-text.c new file mode 100644 --- /dev/null +++ b/clang/test/Sema/pragma-ms-alloc-text.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s + +void foo(); +#pragma alloc_text("hello", foo) // expected-no-diagnostics +void foo() {} + +static void foo1(); +#pragma alloc_text("hello", foo1) // expected-no-diagnostics +void foo1() {} diff --git a/clang/test/Sema/pragma-ms-alloc-text.cpp b/clang/test/Sema/pragma-ms-alloc-text.cpp --- a/clang/test/Sema/pragma-ms-alloc-text.cpp +++ b/clang/test/Sema/pragma-ms-alloc-text.cpp @@ -34,3 +34,9 @@ void foo5(); // expected-note {{previous declaration is here}} #pragma alloc_text(c, foo5) // expected-error {{'#pragma alloc_text' is applicable only to functions with C linkage}} extern "C" void foo5() {} // expected-error {{declaration of 'foo5' has a different language linkage}} + +extern "C" { +static void foo6(); +#pragma alloc_text(c, foo6) // no-warning +void foo6() {} +}