public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* misusing placement new OR possible cxx bug
@ 2008-10-13 16:11 Ralovich, Kristóf
  2008-10-13 16:16 ` Andrew Thomas Pinski
  2008-10-13 16:50 ` Andreas Schwab
  0 siblings, 2 replies; 4+ messages in thread
From: Ralovich, Kristóf @ 2008-10-13 16:11 UTC (permalink / raw)
  To: gcc-bugs

Hi GCC developers,

I have a c++ source, that I think is wrong (wrt the c++ standard), but
accepted by g++ (and msvc too)!

----------------------------------------

int
main(int argc, char** argv)
{
  char* d = new char[256, 256];
  return 0;
}

----------------------------------------

Is this the use of 'placement new' in weird syntax I didn't know
before, or is this code wrong and accidentally accepted by gcc? In the
former case, please correct me and sorry for the noise!


Thanks,
Kristof


PS.: my 'g++ -v' says:

Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian
4.3.2-1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--enable-mpfr --enable-targets=all --enable-cld
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1)

PS2.: Please CC me!


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: misusing placement new OR possible cxx bug
  2008-10-13 16:11 misusing placement new OR possible cxx bug Ralovich, Kristóf
@ 2008-10-13 16:16 ` Andrew Thomas Pinski
  2008-10-13 16:50 ` Andreas Schwab
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Thomas Pinski @ 2008-10-13 16:16 UTC (permalink / raw)
  To:  Ralovich, Kristóf ; +Cc: gcc-bugs



Sent from my iPhone

On Oct 13, 2008, at 9:10 AM, "Ralovich, Kristóf" <kristof.ralovich@gmail.co 
m> wrote:

> Hi GCC developers,
>
> I have a c++ source, that I think is wrong (wrt the c++ standard), but
> accepted by g++ (and msvc too)!
>
> ----------------------------------------
>
> int
> main(int argc, char** argv)
> {
>  char* d = new char[256, 256];
>  return 0;
> }
>
> ----------------------------------------
>
> Is this the use of 'placement new' in weird syntax I didn't know
> before, or is this code wrong and accidentally accepted by gcc? In the
> former case, please correct me and sorry for the noise!
>

This is neither.  The code is using the comma operator.

Thanks,
Andrew Pinski


>
> Thanks,
> Kristof
>
>
> PS.: my 'g++ -v' says:
>
> Using built-in specs.
> Target: i486-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Debian
> 4.3.2-1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
> --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
> --enable-shared --with-system-zlib --libexecdir=/usr/lib
> --without-included-gettext --enable-threads=posix --enable-nls
> --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3
> --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
> --enable-mpfr --enable-targets=all --enable-cld
> --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
> --target=i486-linux-gnu
> Thread model: posix
> gcc version 4.3.2 (Debian 4.3.2-1)
>
> PS2.: Please CC me!


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: misusing placement new OR possible cxx bug
  2008-10-13 16:11 misusing placement new OR possible cxx bug Ralovich, Kristóf
  2008-10-13 16:16 ` Andrew Thomas Pinski
@ 2008-10-13 16:50 ` Andreas Schwab
  2008-10-13 17:11   ` Ralovich, Kristóf
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2008-10-13 16:50 UTC (permalink / raw)
  To: Ralovich, Kristóf; +Cc: gcc-bugs

"Ralovich, Kristóf" <kristof.ralovich@gmail.com> writes:

> ----------------------------------------
>
> int
> main(int argc, char** argv)
> {
>   char* d = new char[256, 256];
>   return 0;
> }
>
> ----------------------------------------
>
> Is this the use of 'placement new' in weird syntax I didn't know
> before, or is this code wrong and accidentally accepted by gcc? In the
> former case, please correct me and sorry for the noise!

$ gcc -Wunused-value -c new.cc
new.cc: In function 'int main(int, char**)':
new.cc:4: warning: left-hand operand of comma has no effect

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: misusing placement new OR possible cxx bug
  2008-10-13 16:50 ` Andreas Schwab
@ 2008-10-13 17:11   ` Ralovich, Kristóf
  0 siblings, 0 replies; 4+ messages in thread
From: Ralovich, Kristóf @ 2008-10-13 17:11 UTC (permalink / raw)
  To: Andreas Schwab, Andrew Thomas Pinski; +Cc: gcc-bugs

On Mon, Oct 13, 2008 at 18:49, Andreas Schwab <schwab@suse.de> wrote:
> "Ralovich, Kristóf" <kristof.ralovich@gmail.com> writes:
>
>> ----------------------------------------
>>
>> int
>> main(int argc, char** argv)
>> {
>>   char* d = new char[256, 256];
>>   return 0;
>> }
>>
>> ----------------------------------------
>>
>> Is this the use of 'placement new' in weird syntax I didn't know
>> before, or is this code wrong and accidentally accepted by gcc? In the
>> former case, please correct me and sorry for the noise!
>
> $ gcc -Wunused-value -c new.cc
> new.cc: In function 'int main(int, char**)':
> new.cc:4: warning: left-hand operand of comma has no effect
>
> Andreas.
>
> --
> Andreas Schwab, SuSE Labs, schwab@suse.de
> SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
> PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
>

Thank you for the fair explanation! I have learned something new
today! I am going to find out more about 'operator comma'. BTW
-Wunused-value is quite useful!

Kristof

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-10-13 17:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-13 16:11 misusing placement new OR possible cxx bug Ralovich, Kristóf
2008-10-13 16:16 ` Andrew Thomas Pinski
2008-10-13 16:50 ` Andreas Schwab
2008-10-13 17:11   ` Ralovich, Kristóf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).