This is an archive of the discontinued LLVM Phabricator instance.

Recover from missing typenames on template args for MSVC compatibility
ClosedPublic

Authored by rnk on Jun 6 2014, 3:55 PM.

Details

Summary

While matching a non-type template argument against a known template
type parameter we now modify the AST's TemplateArgumentLoc to assume the
user wrote typename. Under -fms-compatibility, we downgrade our
diagnostic from an error to an extwarn.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk updated this revision to Diff 10193.Jun 6 2014, 3:55 PM
rnk retitled this revision from to Recover from missing typenames on template args for MSVC compatibility.
rnk updated this object.
rnk added a reviewer: rsmith.
rnk added a subscriber: Unknown Object (MLST).
rsmith added inline comments.Jun 9 2014, 6:42 PM
include/clang/Basic/DiagnosticSemaKinds.td
3115 ↗(On Diff #10193)

This diagnostic text isn't going to work well with -fms-extensions -pedantic-errors. Maybe phrase this more similarly to the existing cases:

"template argument for template type parameter must be a type; omitted 'typename' is a Microsoft extension"

(I'm also not convinced that we should call this a "Microsoft extension", but I can live with it.)

lib/Sema/SemaExpr.cpp
2196 ↗(On Diff #10193)

Our policy for fixits is to only put them on errors/warnings if we recover as if the fixit were applied (this is important for -fixit behavior). Either remove the fixit for now or move it to a note.

lib/Sema/SemaTemplate.cpp
5921–5923 ↗(On Diff #10193)

This comment doesn't look quite right: we don't get here for references to a template-id. We might have an explicit instantiation or an explicit or partial specialization, but the one thing we *don't* have is an implicit instantiation.

This would also make more sense down next to Converted.

rnk added inline comments.Jun 10 2014, 3:00 PM
include/clang/Basic/DiagnosticSemaKinds.td
3115 ↗(On Diff #10193)

I was trying to make the diagnostic more concise, but I can put it back. I think I understand the issue with -pedantic-errors. Is it that we shouldn't make the diagnostic sound like we recovered if it gets upgraded from an ExtWarn to an error?

I agree that "Microsoft extension" is maybe not the best way to describe these types of warnings, but it's consistent with every other -Wmicrosoft diagnostic.

lib/Sema/SemaExpr.cpp
2196 ↗(On Diff #10193)

OK, I'll remove the fixit. The recovery was unnecessary because now we recover prior to instantiation.

lib/Sema/SemaTemplate.cpp
5921–5923 ↗(On Diff #10193)

Woops, this should be reverted. I wrote this when I was half-way through understanding the problem.

rnk updated this revision to Diff 10304.Jun 10 2014, 3:00 PM
  • Fix wording, remove fixit, and revert bad comment
rsmith accepted this revision.Jun 10 2014, 4:12 PM
rsmith edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jun 10 2014, 4:12 PM
rnk closed this revision.Jun 10 2014, 4:37 PM
rnk updated this revision to Diff 10309.

Closed by commit rL210607 (authored by @rnk).