llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Clang generates an error if the enum is defined in the parameter list.

Open llvmbot opened this issue 17 years ago • 2 comments

Bugzilla Link 5477
Resolution FIXED
Resolved on Feb 28, 2012 12:12
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @chandlerc,@jmolloy

Extended Description

If an enum is defined in function parameter list then it should hide the enum of same name defined globally. However clang generates an error saying that enum has previously been defined.

llvmbot avatar Nov 13 '09 05:11 llvmbot

Fixed in r15138.

jmolloy avatar Feb 28 '12 20:02 jmolloy

Ugh. Test case:

#include <stdio.h> enum E1 { A = 1, B = 2 }; void test(enum E1 { A = 3, B = 4 } e1_param) { enum E1 e1_var = e1_param; printf("%d, %d, %d\n", e1_var, A, B); } int main() { test(1); }

First off, Clang is correct to reject this code in C++, but its diagnostics are terrible when this is a redeclaration. If you remove the first definition of E1, the diagnostics from Clang get much better.

Second off, Clang incorrectly rejects this code in C as far as I can tell, but I really don't know if we care. GCC warns on the code pointing out that the enum parameter is probably not what the user wants.

Interestingly, if you remove the first definition, Clang warns in C just like GCC does.... but then it goes and doesn't add that enum to the proper scope for the function, causing an error when we declare a variable. But it does make the enumerators visible. Go figure.

Question: does anyone really care about defining types in parameters? If not, then we can fix this by just making Clang reject such a definition in all cases with a clear error message.

chandlerc avatar Oct 15 '11 01:10 chandlerc