Index: clang/lib/Parse/ParseOpenMP.cpp =================================================================== --- clang/lib/Parse/ParseOpenMP.cpp +++ clang/lib/Parse/ParseOpenMP.cpp @@ -2262,6 +2262,9 @@ } case OMPD_declare_variant: case OMPD_declare_simd: { + // Only allowed in C++ mode + if (!getLangOpts().CPlusPlus && getCurScope()->isClassScope()) + break; // The syntax is: // { #pragma omp declare {simd|variant} } // Index: clang/test/OpenMP/declare_simd_messages.c =================================================================== --- /dev/null +++ clang/test/OpenMP/declare_simd_messages.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp -x c -fms-extensions -Wno-pragma-pack %s + +struct S0 { + // expected-error@+2 {{field 'foo' declared as a function}} + #pragma omp declare simd + void foo(); +}; + +struct S1 { + // expected-error@+3 {{field 'bar' declared as a function}} + // expected-error@+2 {{expected ';' at end of declaration list}} + #pragma omp declare simd + void bar() {} +}; Index: clang/test/OpenMP/declare_variant_messages.c =================================================================== --- clang/test/OpenMP/declare_variant_messages.c +++ clang/test/OpenMP/declare_variant_messages.c @@ -212,3 +212,16 @@ #pragma omp declare variant(foo) match(user = {condition(1)}) // expected-error {{nested user conditions in OpenMP context selector not supported (yet)}} int conflicting_nested_condition(void); #pragma omp end declare variant + +struct S0 { + // expected-error@+2 {{field 'foo' declared as a function}} + #pragma omp declare variant + void foo(); +}; + +struct S1 { + // expected-error@+3 {{field 'bar' declared as a function}} + // expected-error@+2 {{expected ';' at end of declaration list}} + #pragma omp declare variant + void bar() {} +};