[PATCH] D45978: dllexport const variables must have external linkage.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 8 13:55:32 PST 2019


aaron.ballman added a comment.

I think we're pretty close! Some of the testing code can be cleaned up, but I could also use some help verifying that we're correctly matching the behavior of GCC as well.



================
Comment at: test/Sema/dllexport-2.cpp:11
+// expected-warning at +3 {{__declspec attribute 'dllexport' is not supported}}
+// expected-error at +2 {{default initialization of an object of const type}}
+#endif
----------------
I think the pattern to be used here is:
```
#ifdef MSVC
// expected-error at +4 {{'j' must have external linkage when declared 'dllexport'}}
#else
// expected-warning at +2 {{__declspec attribute 'dllexport' is not supported}}
#endif
__declspec(dllexport) int const j; // expected-error {{default initialization of an object of const type 'const int'}}
```


================
Comment at: test/Sema/dllexport-2.cpp:25
+#endif
+__declspec(dllexport) CInt j2;
+
----------------
Same here as above.


================
Comment at: test/SemaCXX/dllexport.cpp:72-74
+#ifndef MS
 namespace    { __declspec(dllexport) int InternalGlobal; } // expected-error{{'(anonymous namespace)::InternalGlobal' must have external linkage when declared 'dllexport'}}
+#endif
----------------
I don't have a copy of mingw handy -- can you test that this behavior matches the behavior when targeting mingw32 with GCC? Might also be a good idea to test cygwin as a target as well. I would have thought that they would behave the same as MSVC, but I can't easily test it myself.


================
Comment at: test/SemaCXX/dllexport.cpp:129
 template<typename T> __declspec(dllexport) Internal InternalTypeVarTmpl; // expected-error{{'InternalTypeVarTmpl' must have external linkage when declared 'dllexport'}}
+#ifndef MS
 namespace    { template<typename T> __declspec(dllexport) int InternalVarTmpl; } // expected-error{{'(anonymous namespace)::InternalVarTmpl' must have external linkage when declared 'dllexport'}}
----------------
Same question here as above.


================
Comment at: test/SemaCXX/dllimport.cpp:124
 __declspec(dllimport) Internal InternalTypeGlobal; // expected-error{{'InternalTypeGlobal' must have external linkage when declared 'dllimport'}}
+#ifndef MS
 namespace    { __declspec(dllimport) int InternalGlobal; } // expected-error{{'(anonymous namespace)::InternalGlobal' must have external linkage when declared 'dllimport'}}
----------------
Likewise here.


================
Comment at: test/SemaCXX/dllimport.cpp:218
 template<typename T> __declspec(dllimport) Internal InternalTypeVarTmpl; // expected-error{{'InternalTypeVarTmpl' must have external linkage when declared 'dllimport'}}
+#ifndef MS
 namespace    { template<typename T> __declspec(dllimport) int InternalVarTmpl; } // expected-error{{'(anonymous namespace)::InternalVarTmpl' must have external linkage when declared 'dllimport'}}
----------------
and here


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D45978/new/

https://reviews.llvm.org/D45978





More information about the cfe-commits mailing list