This is an archive of the discontinued LLVM Phabricator instance.

Avoid extra messages if a template is declared in wrong place.
AbandonedPublic

Authored by sepavloff on Feb 1 2015, 12:10 PM.

Details

Reviewers
None
Summary

If a template is declared in a scope, where it may not, do not mark it
as invalid declaration. Name lookup then can find the declaration, this
reduce number of diagnostic messages.

For instance, the code:

extern "C" {
  namespace ns11416 {
    template <class R> class Sphere_d;
    template <class R> bool equal_as_sets(const Sphere_d<R>&, const Sphere_d<R>&);
  }
}

produces:

pr11416.cpp:3:5: error: templates must have C++ linkage
    template <class R> class Sphere_d;
    ^~~~~~~~~~~~~~~~~~
pr11416.cpp:4:49: error: unknown type name 'Sphere_d'
    template <class R> bool equal_as_sets(const Sphere_d<R>&, const Sphere_d<R>&);
                                                ^
pr11416.cpp:4:57: error: expected ')'
    template <class R> bool equal_as_sets(const Sphere_d<R>&, const Sphere_d<R>&);
                                                        ^
pr11416.cpp:4:42: note: to match this '('
    template <class R> bool equal_as_sets(const Sphere_d<R>&, const Sphere_d<R>&);
                                         ^
pr11416.cpp:4:5: error: templates must have C++ linkage
    template <class R> bool equal_as_sets(const Sphere_d<R>&, const Sphere_d<R>&);
    ^~~~~~~~~~~~~~~~~~

With this patch only messages 'templates must have C++ linkage' are produced.
GCC also does not emit extra messages.

Diff Detail

Event Timeline

sepavloff updated this revision to Diff 19113.Feb 1 2015, 12:10 PM
sepavloff retitled this revision from to Avoid extra messages if a template is declared in wrong place..
sepavloff updated this object.
sepavloff edited the test plan for this revision. (Show Details)
sepavloff updated this object.Feb 1 2015, 12:26 PM
sepavloff added a subscriber: Unknown Object (MLST).

Sending the patch...

sepavloff abandoned this revision.Aug 14 2015, 11:23 AM
sepavloff removed a reviewer: rsmith.
sepavloff removed a subscriber: cfe-commits.

There must be more general way to cope with this problem.