This is an archive of the discontinued LLVM Phabricator instance.

[AST] Assert that no type class is polymorphic
ClosedPublic

Authored by riccibruno on Dec 3 2018, 8:09 AM.

Details

Summary

Add a static_assert checking that no type class is polymorphic.
People should use LLVM style RTTI instead.

Diff Detail

Repository
rL LLVM

Event Timeline

riccibruno created this revision.Dec 3 2018, 8:09 AM
aaron.ballman added inline comments.Dec 3 2018, 10:31 AM
lib/AST/Type.cpp
299 ↗(On Diff #176414)

This will squish your class name and error text together. I think you need a whitespace before "Type" and make that lowercase.

301 ↗(On Diff #176414)

I'd feel more comfortable if there was a #undef TYPE here.

riccibruno marked 2 inline comments as done.Dec 3 2018, 10:40 AM
riccibruno added inline comments.
lib/AST/Type.cpp
299 ↗(On Diff #176414)

This is on purpose, since what is substituted into
CLASS is the name of the type class, without the "Type",
eg: for FunctionProtoType, CLASS will be FunctionProto
and we want to stick the Type to it so that the error message will
be "FunctionProtoType should not ....".

301 ↗(On Diff #176414)

I can certainly add one but it is already done in TypeNodes.def.

aaron.ballman accepted this revision.Dec 3 2018, 10:44 AM

LGTM!

lib/AST/Type.cpp
299 ↗(On Diff #176414)

Ah! Thank you for pointing that out.

301 ↗(On Diff #176414)

Ah, nm then -- I didn't see we had that at the bottom of that file.

This revision is now accepted and ready to land.Dec 3 2018, 10:44 AM
This revision was automatically updated to reflect the committed changes.