Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -55220,6 +55220,16 @@ is TRUE if the expression is the immediate operand of an "&" operator.
&sym->decl_position);
sym->variant.constant = con;
} /* if */
} else if ((fund_sym->is_class_member ||
symbol_is(fund_sym, sk_constant)) &&
!fund_sym->potentially_overloaded &&
!symbol_is_or_contains_template(fund_sym) &&
!(is_simple_function_symbol(fund_sym) &&
template_arg_list_for_symbol(fund_sym) != NULL)) {
/* A non-template member or enumerator cannot be named by a
template-id. Non-member calls may still find a template
through ADL. */
sym = NULL;
} /* if */
} /* if */
if (sym == NULL) {
Expand Down
13 changes: 13 additions & 0 deletions src/pending_changes/gh-598-dependent-template-ids.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[GH #598]
Dependent template-ids naming non-template members

Previously, when a dependent template-id named a non-template class member
Comment thread
mbaluda marked this conversation as resolved.
Resolved
or enumerator after substitution, the front end did not treat it as a
substitution failure. As a result, an overload that should have been
discarded could be selected, leading to a spurious error. For example,
with --c++11:

struct S { int f(); };
template<typename T> int g(decltype(&T::template f<>));
template<typename T> char g(...);
int x = sizeof(g<S>(0)); // Previously a spurious error, now okay.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=1 --c++11 Test_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=2 --c++14 Test_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=3 --c++20 Test_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=4 --c++20 --gnu_version 150300 Test_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=5 --c++20 --clang_version 190100 Test_name.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fe_only -DTEST_NUMBER=6 --ms_c++20 --microsoft_version 1950 Test_name.c
57 changes: 57 additions & 0 deletions tests/tests/regressions/gh-598-dependent-member-template.sft.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//type:fp
//options:--c++11:--c++14:--c++20:--c++20 --gnu_version 150300:--c++20 --clang_version 190100:--ms_c++20 --microsoft_version 1950

template<class...> using void_t = void;
template<class T, class = void> struct has_f {
static const bool value = false;
};
template<class T> struct has_f<T, void_t<decltype(&T::template f<>)>> {
static const bool value = true;
};

template<class T, class = void> struct has_call_f {
static const bool value = false;
};
template<class T> struct has_call_f<T, void_t<decltype(T::template f<>(0))>> {
static const bool value = true;
};

struct Plain { int f() const; };
struct Generic { template<class = void> int f() const; };
struct Overloaded { static int f(int); static int f(double); };
struct OverloadedGeneric {
static int f(double);
template<class = void> static int f(int);
};
struct Data { int f; };
struct StaticData { static int f; };

static_assert(!has_f<Plain>::value, "");
static_assert(!has_f<Overloaded>::value, "");
static_assert(!has_f<Data>::value, "");
static_assert(!has_f<StaticData>::value, "");
static_assert(has_f<Generic>::value, "");
static_assert(has_f<OverloadedGeneric>::value, "");
static_assert(!has_call_f<Overloaded>::value, "");
static_assert(has_call_f<OverloadedGeneric>::value, "");

#if __cpp_variable_templates >= 201304L
struct StaticGeneric { template<class = void> static int f; };
static_assert(has_f<StaticGeneric>::value, "");
#endif

#if __cpp_concepts >= 201907L
namespace N {
struct S {};
template<typename = void> int f(S);
}
int f();
template<typename T> auto g(T t) -> decltype(f<>(t));
static_assert(sizeof(g(N::S{})) == sizeof(int));

struct S { enum { E }; };
enum class ScopedEnum { E };
template<typename T> concept C = requires { T::template E<>; };
static_assert(!C<S>);
static_assert(!C<ScopedEnum>);
#endif
Loading