You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expand annotation check for -Wunique-object-duplication on Windows. (#145944)
Since dllexport/dllimport annotations don't propagate the same way as
visibility, the unique object duplication warning needs to check both
the object in question and its containing class. Previously, we
restricted this check to static data members, but it applies to all
objects inside a class, including functions. Not checking functions
leads to false positives, so remove that restriction.
// Tests here are sparse because the AddrTest case below will define plenty
178
-
// more, which aren't problematic to define (because they're immutable), but
179
-
// may still cause problems if their address is taken.
180
176
};
181
177
182
178
inlinefloat Test::disallowedStaticMember2 = 2.3; // hidden-warning {{'disallowedStaticMember2' may be duplicated when built into a shared library: it is mutable, with external linkage and hidden visibility}}
@@ -211,3 +207,44 @@ inline int allowedTemplate2 = 0;
// Unlike visibility, declexport annotations do not propagate down to nested
217
+
// classes. Hence on windows, we only avoid duplication of class members if
218
+
// their immediate containing class is annotated. On posix, we get avoid
219
+
// duplication if any containing class is annotated.
220
+
221
+
classVISIBLE Outer {
222
+
// Visible because their class is exported
223
+
inlinestaticint allowedOuterMember = 0;
224
+
int* allowedOuterFunction() {
225
+
staticint allowed = 0;
226
+
return &allowed;
227
+
}
228
+
229
+
// No annotation, and visibility is only propagated on posix.
230
+
classHiddenOnWindows {
231
+
inlinestaticint disallowedInnerMember = 0; // windows-warning {{'disallowedInnerMember' may be duplicated when built into a shared library: it is mutable, with external linkage and no import/export annotation}}
232
+
233
+
234
+
int* disallowedInnerFunction() {
235
+
staticint disallowed = 0; // windows-warning {{'disallowed' may be duplicated when built into a shared library: it is mutable, with external linkage and no import/export annotation}}
0 commit comments