[LLVMbugs] [Bug 18176] New: cmath: compile failure with custom fabs in std namespace

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Dec 7 23:13:27 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=18176

            Bug ID: 18176
           Summary: cmath: compile failure with custom fabs in std
                    namespace
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: hhinnant at apple.com
          Reporter: amdmi3 at amdmi3.ru
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 11687
  --> http://llvm.org/bugs/attachment.cgi?id=11687&action=edit
Fix

When fabs() overload for custom type is added to std namespace, cmath won't
compile. Example code:

% cat test.cc
struct mytype {
};

namespace std {
    mytype fabs(const mytype& a) {
        return mytype();
    }
}

#include <cmath>

int main() {
    mytype a;
    a = std::fabs(a);

    return 0;
}
% clang++ test.cc
In file included from test.cc:10:
/usr/include/c++/v1/cmath:664:35: error: no matching function for call to
'fabs'
abs(double __x) _NOEXCEPT {return fabs(__x);}
                                  ^~~~
4.cc:5:9: note: candidate function not viable: no known conversion from
'double' to 'const mytype' for 1st argument
        mytype fabs(const mytype& a) {
               ^
1 error generated.

Fix is attached. Similar fix may be needed for other functions from global
namespace.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131208/06dddc12/attachment.html>


More information about the llvm-bugs mailing list