[LLVMbugs] [Bug 12841] New: Invalid Name Redefinition Error
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue May 15 22:16:13 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=12841
Bug #: 12841
Summary: Invalid Name Redefinition Error
Product: clang
Version: 3.0
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: turbobafalcon at hotmail.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
This is using the most up-to-date build for OpenSUSE 12.1 on x86-64 (clang
version 3.0 (branches/release_30 145598)).
Example code producing the error is provided below. The code compiles correctly
on GCC 4.6. I expect that the bool varName variable declared in the if
statement should be available to all sub-blocks but should not prevent them
from declaring another variable with the same name (however poor that may be in
terms of coding style).
The error that I get is the following:
test.cpp:7:13: error: redefinition of 'varName' with a different type
const int varName = 0;
^
test.cpp:5:11: note: previous definition is here
if (bool varName = (a_argc == 1))
^
test.cpp:16:13: error: redefinition of 'varName' with a different type
const int varName = 1;
^
test.cpp:5:11: note: previous definition is here
if (bool varName = (a_argc == 1))
^
2 errors generated.
I wouldn't be surprised if this has already been fixed, but I couldn't find a
duplicate report.
>>>>>>>>>>>>>>>>>>>Contents of test.cpp<<<<<<<<<<<<<<<<<<<<<<<<<
#include <iostream>
int main(int a_argc, char * a_argv[])
{
if (bool varName = (a_argc == 1))
{
const int varName = 0;//GENERATES ERROR
std::cout << "branch a" << std::endl;
}
//Uncommenting this will fix the problem in the block below,
//same as if you surround it with an extra set of braces.
//else if (false)
//{
//}
else
{
const int varName = 1;//GENERATES ERROR
std::cout << "branch b" << std::endl;
}
}
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list