PING: [PATCH: c++/diagnostic/18313] Warn for pointless qualifiers on return type

Mark Mitchell
Tue Nov 14 04:57:00 GMT 2006

Dirk Mueller wrote:

> template<typename T> class Pair
> {
>     public:
>         ....
>         T getLeft() const;
>         const T getRight() const;
> };
> when there is a Pair<const int> instantiation, you want calls of "getLeft" to 
> warn? How about "getRight" (in the <const int> case, and in the <int> case)?

I think the simplest answer is that all three cases should warn.  I
understand why that's not necessarily a good thing, but it does preserve
the invariant that warnings you get during instantiation are the same as
those you get outside of an instantiation.

If we want to be more sophisticated, then I think maybe we should
distinguish dependent cases from non-dependent cases.  For example, maybe:

  template <typename T> struct S {
    const int f(); // Should warn -- "const int" is not dependent.
    const T g(); // No warning.
    T h(); // Warning if T is "const int"?

The EDG front end seems not to warn on either of the dependent cases,
which is in keeping with your original approach.

I'm not sure what to suggest.  The EDG behavior is certainly best at
avoiding false positives, but is it what we really want?  Nathan, Jason,
what say you?

>> I think maybe SCALAR_TYPE_P is what you're looking for?
> "const void dofoo();" fails SCALAR_TYPE_P. 

Ah, right, good point!  I still think SCALAR_TYPE_P || VOID_TYPE_P might
be a clearer representation that IS_AGGR_TYPE, whose semantics are not
as well-defined, in the sense that it doesn't map as nicely onto terms
from the C++ standard.


Mark Mitchell
(650) 331-3385 x713

More information about the Gcc-patches mailing list