Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<valarray>: Inconsistent use of ADL #285

Closed
cpplearner opened this issue Nov 10, 2019 · 1 comment
Closed

<valarray>: Inconsistent use of ADL #285

cpplearner opened this issue Nov 10, 2019 · 1 comment
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@cpplearner
Copy link
Contributor

Describe the bug
Non-member functions in <valarray> are inconsistent about whether to use ADL.

abs enables ADL:

STL/stl/inc/valarray

Lines 749 to 752 in f9b1dcc

template <class _Ty>
_NODISCARD valarray<_Ty> abs(const valarray<_Ty>& _Left) {
_VALOP(_Ty, _Left.size(), abs(_Left[_Idx]));
}

Other functions disable ADL by qualify the function call with _CSTD. For example:

STL/stl/inc/valarray

Lines 834 to 837 in f9b1dcc

template <class _Ty>
_NODISCARD valarray<_Ty> sqrt(const valarray<_Ty>& _Left) {
_VALOP(_Ty, _Left.size(), _CSTD sqrt(_Left[_Idx]));
}

Both libstdc++ and libc++ use ADL for all these functions.

Command-line test case
STL version (git commit or Visual Studio version): 19.24.28218.2

D:\>type test.cpp
#include <valarray>

namespace ns {
    struct A {};

    A abs(A);
    A sqrt(A);
}

int main() {
    std::valarray<ns::A> a;
    (void)std::abs(a);
    (void)std::sqrt(a);
}

D:\>cl /c test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28218.2 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp
D:\...\valarray(836): error C2665: 'sqrt': none of the 3 overloads could convert all the argument types
D:\...\cmath(485): note: could be 'long double sqrt(long double) noexcept'
D:\...\cmath(241): note: or       'float sqrt(float) noexcept'
D:\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_math.h(485): note: or       'double sqrt(double)'
D:\...\valarray(836): note: while trying to match the argument list '(const _Ty)'
        with
        [
            _Ty=ns::A
        ]
test.cpp(11): note: see reference to function template instantiation 'std::valarray<ns::A> std::sqrt<ns::A>(const std::valarray<ns::A> &)' being compiled

Expected behavior
No error.

Additional context
N/A

@miscco
Copy link
Contributor

miscco commented Nov 10, 2019

That seems to indeed be a bug. From valarray.transcend $1:

Requires: Each of these functions may only be instantiated for a type T to which a unique function with the indicated name can be applied (unqualified).
This function shall return a value which is of type T or which can be unambiguously implicitly converted to type T.

So each of those functions should be indeed called unqualified.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Nov 11, 2019
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
Development

No branches or pull requests

3 participants