This is an archive of the discontinued LLVM Phabricator instance.

Improve error message when referencing a non-tag type with a tag
ClosedPublic

Authored by rnk on Oct 3 2016, 5:22 PM.

Details

Summary

Other compilers accept invalid code here that we reject, and we need a
better error message to try to convince users that the code is really
incorrect. Consider:

class Foo {
  typedef MyIterHelper<Foo> iterator;
  friend class iterator;
};

Previously our wording was "elaborated type refers to a typedef".
"elaborated type" isn't widely known terminology, so the new diagnostic
tries to talk about tag types.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk updated this revision to Diff 73380.Oct 3 2016, 5:22 PM
rnk retitled this revision from to Improve error message when referencing a non-tag type with a tag.
rnk updated this object.
rnk added a reviewer: rsmith.
rnk added a subscriber: cfe-commits.
rnk added a comment.Nov 30 2016, 1:32 PM

Ping, found this in my tree. Maybe you weren't that excited about the wording change.

rnk updated this revision to Diff 79805.Nov 30 2016, 1:33 PM
  • rebase

I like it. I'll give others a little time to respond, but if no objections are raised and nobody else accepts first, I'll accept it tomorrow.

rsmith added inline comments.Nov 30 2016, 2:08 PM
include/clang/Basic/DiagnosticSemaKinds.td
4556–4558 ↗(On Diff #79805)

"tag" is C terminology that C++ doesn't share; "specifier" would be correct in both languages.

Also, this wording suggests that *some* templates / template template arguments / ... can be referenced by, say, a struct specifier. How about:

%select{non-struct type|non-class type|non-union type|non-enum type|typedef|type alias|template|[...]}1 %0 cannot be referenced with %select{struct|interface|union|class|enum}2 specifier

(where we use "non-enum type" when the tag is enum, "non-union type" when the tag is union, and otherwise use "non-struct type" in C and "non-class type" in C++)?

rnk added inline comments.Nov 30 2016, 4:14 PM
include/clang/Basic/DiagnosticSemaKinds.td
4556–4558 ↗(On Diff #79805)

OK, sounds good.

rnk updated this revision to Diff 80903.Dec 9 2016, 8:22 AM
  • new wording
rsmith accepted this revision.Dec 9 2016, 9:50 AM
rsmith edited edge metadata.

Thanks!

This revision is now accepted and ready to land.Dec 9 2016, 9:50 AM
This revision was automatically updated to reflect the committed changes.