[LLVMbugs] [Bug 14785] New: clang++ ignores friend function definition within class scope (allowing redefinition)
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Jan 2 09:53:52 PST 2013
http://llvm.org/bugs/show_bug.cgi?id=14785
Bug #: 14785
Summary: clang++ ignores friend function definition within
class scope (allowing redefinition)
Product: clang
Version: 3.2
Platform: PC
OS/Version: All
Status: NEW
Keywords: accepts-invalid, miscompilation
Severity: normal
Priority: P
Component: C++11
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: irrequietus at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 9798
--> http://llvm.org/bugs/attachment.cgi?id=9798
original testcase file used (ill formed code that compiles, but should not)
Hello,
The following code snippet is ill - formed and clang++ should not compile it
warning of redefinition, however it is accepted as legal. There can be several
variations of this snippet and I am simply posting one of them.
In brief, in - class scope friend function *definition* is ignored when lookup
is performed. Affected are both C++03 and C++11 implementations of the standard
in clang++ at least in the following versions I could test:
================================================================================
clang version 3.1 (release), 3.2 (release), and r170492
================================================================================
#include <cstdio>
template<typename T>
struct Somewhat {
private:
void internal() const
{ printf("internal called\n"); }
public:
friend void operator+(int const &, Somewhat<T> const &)
{} // notice the in - class scope definition
};
void operator+(int const &, Somewhat<char> const &x)
{ x.internal(); }
int main() {
// internal() called, the friend in - class *definition* ignored.
1 + Somewhat<char>();
return 0;
}
================================================================================
gcc (4.6.3, 4.7.1, 4.7.2 and 4.8.x snapshot tested) and icc (13.0.0 20120731 as
I am informed) give an error informing the user of a redefinition error for the
operator+ function as per language standard, while clang++ ignores completely
the in - class scope definition of the friend function.
Any help?
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list