On Mon, Aug 25, 2025 at 06:43:11PM +0200, Jakub Jelinek wrote: > On Mon, Aug 25, 2025 at 10:23:52AM -0600, Sandra Loosemore wrote: > > On 8/25/25 09:29, Jakub Jelinek wrote: > > > On Mon, Aug 25, 2025 at 09:13:58AM -0600, Sandra Loosemore wrote: > > > > How? Declare variant substitution presently happens primarily during > > > > gimplification which is way before any vectorization happens. And > > > > fixing > > > > the various bugs esp in the C++ front end with regard to doing the name > > > > lookup/template expansion/overload resolution using the actual > > > > arguments at > > > > the call site will move the generation of the call_expr to the variant > > > > even > > > > > > That is not what should be done. The lookup should be done at the declare > > > variant declaration side, that is how the design has been since that > > > meeting. The compiler records the variants and later on just picks from > > > that list of variants based on the condition. > > > > Starting with OpenMP 5.2, the spec explicitly says differently for C++: > > > > "The function variant is determined by base language standard name lookup > > rules ([basic.lookup]) of variant-name using the argument types at the call > > site..." > > I think https://github.com/OpenMP/spec/issues/1852 should be reopened for > that, that call site part is an error.
Note, clang++ seems to implement it like gcc: Try say: https://godbolt.org/z/4E3bx8Kr8 void foo (long); void foo (int); #pragma omp declare variant (foo) match (construct={parallel}) void bar (int); namespace N { void foo (int); void baz () { auto foo = [] (int) {}; bar (1); #pragma omp parallel bar (2); } } With the 2 foo declarations commented out, it errors, otherwise calls ::bar (1) and ::foo (2), not N::foo (2) or N::baz()::lambda::operator()(2) It would be really weird if #pragma omp declare variant (foo) match (construct={parallel}) void bar (int); was meant to be valid C++ (because the lookup is done only at call sites) and not valid C (where the lookup is done on the declaration) or to the Fortran equivalent (where again the standard is very specific that it is resolved at the location of the directive). The original design has been that the lookup would be done as if say the declare variant declaration was inline function definition that called the variant-name with the provided arguments. Jakub