Bug 39040 - Redeclaration
Summary: Redeclaration
Status: RESOLVED DUPLICATE of bug 39038
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-30 05:01 UTC by mahesh.balasubramanian
Modified: 2009-01-30 07:21 UTC (History)
2 users (show)

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 mahesh.balasubramanian 2009-01-30 05:01:23 UTC
Hello,

I found a strange behavior of the following code.

void fn(int x, int y){
 if(int temp = ( x > y ? (x /y) : (x % y))){
  cout << temp;
 }
 else{
  double temp = x / y; // ill-formed, redeclaration of temp
  cout << temp;
 }
}

int main(int argc, char **argv){
 fn(2, 3);
}

According to $6.4/3 (14882_1998), This code is ill-formed. But g++ does not through any error or warning.

But comeau and vc++ are throwing errors.

$6.4/3
A name introduced by a declaration in a condition (either introduced by the type-specifier-seq or the declarator of the condition) is in scope from its point of declaration until the end of the substatements controlled by the condition. If the name is re-declared in the outermost block of a substatement controlled by the condition, the declaration that re-declares the name is ill-formed.

Thanks and Regards,
Mahesh. B
Comment 1 Richard Biener 2009-01-30 07:21:32 UTC

*** This bug has been marked as a duplicate of 39038 ***