Closed
Description
Title: [GCC] UFCS with qualified function fails.
Description:
Clang and MSVC accept: https://compiler-explorer.com/z/qb19TEGv1.
I haven't reported this before because I was sure that
UFCS is for member call syntax and a qualified function doesn't make sense there.
But Herb has used such calls before, and it might be actually useful: #741 (comment).
Minimal reproducer (https://cpp2.godbolt.org/z/5MTr6jcsh):
ns: namespace = {
f: (_) = { }
}
main: () = {
_ = 0.ns::f();
}
Commands:
cppfront main.cpp2
g++14 -std=c++23 -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp
Expected result:
- A diagnostic by Cppfront, or
- GCC to work (maybe it's their bug), or
- if this is a feature, for a qualified function in a member function call syntax
to lower without the UFCS macro as a free function call because a member call would never work anyways.
Actual result and error:
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
namespace ns {
}
//=== Cpp2 type definitions and function declarations ===========================
namespace ns {
auto f([[maybe_unused]] auto const& param1) -> void;
}
auto main() -> int;
//=== Cpp2 function definitions =================================================
namespace ns {
auto f([[maybe_unused]] auto const& param1) -> void{}
}
auto main() -> int{
static_cast<void>(CPP2_UFCS_0(ns::f, 0));
}
Output:
build/main.cpp: In lambda function:
build/main.cpp:27:33: error: 'ns::f' is not a class member
27 | static_cast<void>(CPP2_UFCS_0(ns::f, 0));
| ^~
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:761:47: note: in definition of macro 'CPP2_UFCS_0'
761 | if constexpr (requires{ CPP2_FORWARD(obj).FUNCNAME(); }) { \
| ^~~~~~~~
build/main.cpp:27:33: error: 'ns::f' is not a class member
27 | static_cast<void>(CPP2_UFCS_0(ns::f, 0));
| ^~
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:762:34: note: in definition of macro 'CPP2_UFCS_0'
762 | return CPP2_FORWARD(obj).FUNCNAME(); \
| ^~~~~~~~