Consider:

  template <typename Derived>
  struct Base { Derived * f() { return static_cast<Derived const *>(this); } };

  struct D: Base<D> {};

  int main() { D d; d.f(); }

This code is ill-formed, because f is declared to return a Derived*, but the
return statement specifies an expression of type Derived const*.

However, g++ accepts the code without any diagnostic.

Comeau 4.3.10.1 /does/ diagnose the problem, saying "error: return value type
does not match the function type".


-- 
           Summary: Undiagnosed const violation in pointer conversion in
                    CRTP context.
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc-bugzilla at contacts dot eelis dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38020

  • [Bug c++/38020] New: Undiagnos... gcc-bugzilla at contacts dot eelis dot net

Reply via email to