https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118530
Bug ID: 118530
Summary: [OpenMP] declare_variant - non-arg variant with
non-template return value type not selected
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: openmp, rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
CC: jakub at gcc dot gnu.org, waffl3x at protonmail dot com
Target Milestone: ---
Found by my colleague, waffl3x, and a bit related to PR118488.
-----------
template<typename T>
void variant() {}
#pragma omp declare variant(variant) match(implementation={vendor("gnu")})
template<typename T>
void base () {}
int main()
{
base<void>();
}
-----------
The return type is fixed, there is only one variant but the current code
fails to select 'void variant()' as correct candidate:
foo.C: In function ‘void base()’:
foo.C:4:29: error: no matching function for call to ‘variant()’
[-Wtemplate-body]
4 | #pragma omp declare variant(variant)
match(implementation={vendor("gnu")})
| ^~~~~~~
foo.C:4:29: note: there is 1 candidate
foo.C:2:6: note: candidate 1: ‘template<class T> void variant()’
2 | void variant() {}
| ^~~~~~~
foo.C:2:6: note: template argument deduction/substitution failed:
foo.C:4:29: note: couldn’t deduce template parameter ‘T’
4 | #pragma omp declare variant(variant)
match(implementation={vendor("gnu")})
| ^~~~~~~
* * *
Debugging shows that the is processed in omp_declare_variant_finalize_one via
8542 else
8543 variant = finish_call_expr (variant, &args,
/*disallow_virtual=*/false,
8544 koenig_p, tf_warning_or_error);
and there:
3224 if (processing_template_decl)
...
3239 if (type_dependent_expression_p (fn)
3240 || any_type_dependent_arguments_p (*args))
3241 {
...
3275 }
3276 orig_args = make_tree_vector_copy (*args);
...
3300 if (is_overloaded_fn (fn))
3301 fn = baselink_for_fns (fn);
...
3351 else if (is_overloaded_fn (fn))
...
3354 if (TREE_CODE (fn) == FUNCTION_DECL
...
3422 result = build_new_function_call (fn, args, complain);
* * *
And there:
5148 cand = perform_overload_resolution (fn, *args, &candidates,
&any_viable_p,
5149 complain);
returns NULL.
5167 print_error_for_call_failure (fn, *args, candidates);
then prints the error + candidate list shown above.