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

             Bug #: 12028
           Summary: Error for use of 'this' inside operator new should
                    mention that operator new is implicitly static
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified


$ cat test.cc
#include <new>
#include <stdlib.h>

class Foo {
public:
  void* operator new(size_t s) {
    void* result;
    posix_memalign(&result, alignof(*this), s);
    return result;
  }
};
$ clang++ -std=c++11 -stdlib=libc++ -c test.cc
test.cc:8:38: error: invalid use of 'this' outside of a nonstatic member
function
    posix_memalign(&result, alignof(*this), s);
                                     ^
1 error generated.


--------
Users may not realize that operator new is implicitly static, which would make
this error message confusing.  Perhaps add a note: "operator new is implicitly
static"

The general error message isn't great either, with that triple negative: I'd
replace it with "'this' may only be used inside a nonstatic member function."
or, if more wording variations are ok, "'this' used inside static member
function".

-- 
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to