On 02/05/2014 02:36 PM, Peter De Wachter wrote: > On 05-02-14 21:40, Eric Blake wrote: >> Actually, in gcc's case, your proposed program is now a syntax error: >> >> $ gcc -o foo foo.c >> foo.c: In function ‘main’: >> foo.c:1:21: error: ‘new’ undeclared (first use in this function) >> int main() { (void) new int; return 0; }
> > That's because you named the file "foo.c". > > $ gcc -o foo foo.cpp > /tmp/ccVVxj3a.o: In function `main': Oh - so the gcc frontend changes language syntax based on file extension, but does NOT change the linker backend to match. Then yes, I agree that we have to force a linker error. > 'delete new int' should work as well. But I don't think defining a class > is sufficient. To catch GCC, you need something that will cause a link > error. Something like this would work: > > #include <string> > int main() { std::string s; return 0; } Too complex to be reliable. > > But using the standard library is difficult if you want to support old > compilers that don't have namespace support. I think you've convinced me that going with 'delete new int' is the way to go. I'll wait another day or so before pushing, in case anyone else has comments. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature