Bug 48185 - if(struct ...)
Summary: if(struct ...)
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.5.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-18 15:57 UTC by Lisp2D
Modified: 2011-03-18 17:27 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lisp2D 2011-03-18 15:57:49 UTC
Variable definition in structure if() can't receive type struct.

if(struct passwd*pwd(getpwuid(...)))return;

error: expected primary-expression before ‘struct’
error: expected ‘)’ before ‘struct’
Comment 1 Richard Biener 2011-03-18 16:02:01 UTC
That is neither C nor C++.
Comment 2 Lisp2D 2011-03-18 17:15:23 UTC
Code

{ struct passwd*pwd(getpwuid(...));
  if(pwd)return true;}

is still compiled.

Code

if(struct passwd*pwd=getpwuid(...))return;

compiled too.

But 

if(struct passwd*pwd(getpwuid(...)))return;

will not.

Who is right?
Comment 3 Jonathan Wakely 2011-03-18 17:27:43 UTC
G++ is right

a declaration in a selection-statement (if or switch) must be of the form:
  if ( type-specifier id = initializer )
or in C++0x:
  if ( type-specifier id { init } )

See 6.4 in the C++ standard