__declspec(dllimport) strangeness

In testing the AST I came across a strangeness in how the DLLImport
attribute is handled. The following code results in a warning:

void __declspec(dllimport) foo12();
void foo12(){}

The warning is:
'foo12' redeclared without dllimport attribute: previous dllimport ignored

However, the AST for foo12 still has the DLLImport attribute. This seems
wrong to me. At least, it isn't what the warning is suggesting.

The warning is issued in Sema::ActOnStartOfFunctionDef (search for
warn_redeclaration_without_attribute_prev_attribute_ignored). Should the
attribute be removed when the diagnostic is issued?

Hi Eric

Ignoring (and removing) the attribute seems right to me in this case. But I
just wanted to point out that MSVC behaves differently if inline is used:

void __declspec(dllimport) foo12();
inline void foo12(){}

In this case, the MS compiler ignores the discrepancy, and also ignores the
body of foo12 - emitting a reference to an external instead.

Roger Lawrence
Embarcadero

That's just weird. One has to wonder if it's by design. Is clang to be
bug-for-bug compatible with the MS compiler for these MS-specific
extensions? IMO, it would be better if this were an error.

That's just weird. One has to wonder if it's by design. Is clang to be
bug-for-bug compatible with the MS compiler for these MS-specific
extensions? IMO, it would be better if this were an error.

It depends whether such sort of thing can be seen in system
(MS-provided) headers.
If yes, then such an error should be relaxed to MS-provided compiler
implementation.