[PATCH] Fallback to operator new for MSVC compatibility
Richard Smith
richard at metafoo.co.uk
Wed May 29 15:23:02 PDT 2013
On Wed, May 29, 2013 at 1:01 PM, Aaron Ballman <aaron at aaronballman.com>wrote:
> On Wed, May 29, 2013 at 3:55 PM, Richard Smith <richard at metafoo.co.uk>
> wrote:
> > On Wed, May 29, 2013 at 7:49 AM, Aaron Ballman <aaron at aaronballman.com>
> > wrote:
> >>
> >> #include <stdio.h>
> >> #include <stdlib.h>
> >>
> >> struct arbitrary_t {} arbitrary;
> >>
> >> void *operator new[]( size_t s, arbitrary_t ) throw() { return
> ::malloc( s
> >> ); }
> >>
> >> struct S {
> >> void *operator new( size_t s, arbitrary_t ) throw() { return
> ::malloc( s
> >> ); }
> >> };
> >>
> >> int main() {
> >> S *s = new (arbitrary) S[2];
> >> }
> >>
> >> This will yield a call to the global operator new[] instead of the
> >> class-specific operator new. Using new instead of new[] yields a call
> >> to the matching class-specific operator new still. So I think my test
> >> will have to move down below the check for a global operator new:
> >>
> >> <look for member operator new>
> >> <look for global operator new>
> >> +if (not found && looking for array new && MS mode)
> >> + <switch to looking for non-array new>
> >> + <look for global operator new>
> >>
> >> If you agree, then I'll make the changes and add another test to
> >> CodeGenCXX to ensure we're calling the proper one.
> >
> >
> > What happens if you remove the global array new? Is the class-specific
> > non-array new used then?
>
> You get an error:
>
> F:\Aaron Ballman\Desktop\test6.cpp(13) : error C2660: 'operator new' :
> function
> does not take 2 arguments
Weird... well, OK then.
The indentation in SemaExprCXX.cpp in your latest patch looks a bit off
(maybe you ran diff with -b or -w?), otherwise LGTM.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130529/516c9988/attachment.html>
More information about the cfe-commits
mailing list