llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.87k stars 11.93k forks source link

Non-conforming behavior regarding multiple function declarations with default arguments #59363

Open Endilll opened 1 year ago

Endilll commented 1 year ago

[over.match.best]/4 includes an example with ill-formed code that Clang fails to diagnose:

namespace A {
  extern "C" void f(int = 5);
}
namespace B {
  extern "C" void f(int = 5);
}

using A::f;
using B::f;

void use() {
  f(3);             // OK, default argument was not used for viability
  f();              // error: found default argument twice
}

For the reference, [dcl.fct.default]/4 states that "declarations that inhabit different scopes have completely distinct sets of default arguments." There's also a related CWG418 and a D139429 that adds a test for it.

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

llvmbot commented 1 year ago

@llvm/issue-subscribers-c-1

shafik commented 1 year ago

Confirmed: https://godbolt.org/z/sTqPqdeWr

Note gcc also does not catch this but MSVC does.

cor3ntin commented 1 year ago

There is already a bunch of FIXME there https://github.com/llvm/llvm-project/blob/cfd44221e3e1783c0f44d5b1694dfbe84187246a/clang/lib/Sema/SemaLookup.cpp#L395-L407

zygoloid commented 1 year ago

This is CWG1, see https://clang.llvm.org/cxx_dr_status.html#1 and Clang's test cases for that DR, which include a few additional interesting cases that an implementation of this will need to handle.