LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 6741 - Can't have multiple anonymous unions which redeclare members
Summary: Can't have multiple anonymous unions which redeclare members
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: trunk
Hardware: Macintosh MacOS X
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-29 23:32 PDT by Alex Mac
Modified: 2010-09-23 09:26 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
testcase (147 bytes, application/octet-stream)
2010-03-29 23:32 PDT, Alex Mac
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Mac 2010-03-29 23:32:02 PDT
Created attachment 4610 [details]
testcase

Perhaps this is a violation of the spec and clang is right to disallow it, however it does crop up in "real world" code so it *might* be better for this to be a warning rather than an error. Here is a small example of what I'm talking about

p.s. As it happens the one use of this in the AVM code base is entirely frivolous and can easily be removed, but perhaps it affects other codebases...

void foo() {
	union {
		char *m_a;
		int *m_b;
	};
	// some code

	if(somecondition) {
		union {
			char *m_a;
			int *m_b;
		};
		// some code
	}
}

Currently clang gives you the following error:

union-bug.cpp:11:10: error: member of anonymous union redeclares 'm_a'
                        char *m_a;
                              ^
union-bug.cpp:5:9: note: previous declaration is here
                char *m_a;
Comment 1 Argyrios Kyrtzidis 2010-07-30 11:21:18 PDT
This seems like a bogus error. Consider this case:

typedef void *voidPtr;

void f() {
	union { int **ctxPtr; void **voidPtr; };
}


t.cpp:4:31: error: member of anonymous union redeclares 'voidPtr'
        union { int **ctxPtr; void **voidPtr; };
                                     ^
t.cpp:1:15: note: previous declaration is here
typedef void *voidPtr;
              ^
Comment 2 Argyrios Kyrtzidis 2010-09-23 09:26:28 PDT
Fixed at r114641.