Title
What if two using-declarations refer to the same function but the declarations introduce different default-arguments?
Status
tc1
Section
9.3.4.7 [dcl.fct.default]
Submitter
Bill Gibbons

Created on 1998-10-24.00:00:00 last changed 262 months ago

Messages

Date: 2004-09-10.00:00:00

6.4 [basic.scope] paragraph 4 says:

Given a set of declarations in a single declarative region, each of which specifies the same unqualified name,
  • they shall all refer to the same entity, or all refer to functions ...
9.3.4.7 [dcl.fct.default] paragraph 9 says:
When a declaration of a function is introduced by way of a using-declaration (9.9 [namespace.udecl]), any default argument information associated with the declaration is imported as well.
This is not really clear regarding what happens in the following case:
    namespace A {
            extern "C" void f(int = 5);
    }
    namespace B {
            extern "C" void f(int = 7);
    }

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

    f(); // ???
Proposed resolution (10/00):

Add the following at the end of 12.2.4 [over.match.best]:

If the best viable function resolves to a function for which multiple declarations were found, and if at least two of these declarations — or the declarations they refer to in the case of using-declarations — specify a default argument that made the function viable, the program is ill-formed. [Example:
    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
    }

  —end example]

History
Date User Action Args
2003-04-25 00:00:00adminsetstatus: dr -> tc1
2000-11-18 00:00:00adminsetstatus: ready -> dr
2000-05-21 00:00:00adminsetstatus: drafting -> ready
1998-10-24 00:00:00admincreate