This is an archive of the discontinued LLVM Phabricator instance.

[MS ABI] dllimport'd class cannot have constexpr ctors
ClosedPublic

Authored by majnemer on Feb 6 2016, 6:03 PM.

Details

Summary

The installation of a class's vptr cannot be performed without code
being executed. This implies that the constructor of a class cannot be
constexpr.

This fixes PR26506.

Diff Detail

Event Timeline

majnemer updated this revision to Diff 47113.Feb 6 2016, 6:03 PM
majnemer retitled this revision from to [MS ABI] dllimport'd class cannot have constexpr ctors.
majnemer updated this object.
majnemer added reviewers: hans, rsmith, thakis, rnk.
majnemer added a subscriber: cfe-commits.
thakis edited edge metadata.Feb 7 2016, 10:37 AM

Thanks for jumping on this so quickly! Hans can probably just stamp this, but I lack the background, so I must ask:

test/SemaCXX/dllimport.cpp
1262

cl.exe seems to accept this – do you know how they do that? Do they just silently ignore the constexpr?

1269

nit: I feel diagnostics are easier to understand if their text is stand-alone and not spread across diag and its note. That is "dllimported constructors cannot be marked constexpr" "note: dllimported here" or something like this (this also helps with the mythical localization of diagnostics).

majnemer added inline comments.Feb 7 2016, 1:39 PM
test/SemaCXX/dllimport.cpp
1262

They silently ignore the constexpr:

struct __declspec(dllimport) PR26506_test1 {
  virtual ~PR26506_test1() {}
  constexpr PR26506_test1() = default;
};
constexpr PR26506_test1 x;

They report:

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

t.cpp
t.cpp(5): error C2127: 'x': illegal initialization of 'constexpr' entity with a non-constant expression
1269

I chose this style because it is most consistent with our diagnostic for a constexpr constructor for a class with virtual bases.

thakis added a comment.Feb 7 2016, 1:51 PM

Cool, lgtm. Maybe we'll have to downgrade this to a warning eventually since cl allows it, but for now let's see how this goes.

test/SemaCXX/dllimport.cpp
1269

Hm, I suppose I feel we should change those too then :-) (but that's a discussion for somewhere else then)

hans accepted this revision.Feb 8 2016, 9:18 AM
hans edited edge metadata.

lgtm

This revision is now accepted and ready to land.Feb 8 2016, 9:18 AM

Looks like patch was not committed.

thakis closed this revision.Feb 1 2019, 9:36 AM

David landed a better fix in r260388.