https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102444
Bug ID: 102444
Summary: class definition not allowed to change meaning of
previously used name
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gonzalo.gadeschi at gmail dot com
Target Milestone: ---
See http://eel.is/c++draft/class.member.lookup#6
[class.member.lookup]/p6: "If it [the result of the search] differs from the
result of a search in T for N from immediately after the class-specifier of T,
the program is ill-formed, no diagnostic required." A class definition is not
allowed to change the meaning of a name that was already used earlier in the
class definition.
While no diagnostic is required, I think a quality implementation like gcc
should produce a diagnostic here and reject this program since it is
ill-formed.
Example: https://gcc.godbolt.org/z/jhEj68Kq8
struct plus {
template<typename... Args>
using invoke = void;
};
template <typename Fn, typename... Args>
using invoke = typename Fn::template invoke<Args...>;
template <typename Fn>
struct compose
{
template <typename X, typename Y>
using F = invoke<Fn, X, Y>;
template <typename X>
using invoke = invoke<Fn, X, X>;
};
using Q = compose<plus>::F<int, int>;
Is accepted by gcc.