//--------------------------------------
struct X {
struct A {};
typedef int A; // why not conflict?
A m; // why resolve to 'typedef A'?
};
int main() {
X x;
x.m = 1.0; // ok
X::A y; // why resolve to 'struct A'?
y = 1.0; // error
return 0;
}
//----------------------------------------
Thank for your help,
Jason
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
This *should* be ill-formed. If not, this is
a compiler bug. Rationale is 7.1.3/5:
"In a given scope, a typedef specifier shall not be
used to redefine the name of any type declared in
that scope to refer to a different type. [ Example:
class complex { / ... / };
typedef int complex; // error: redefinition
—end example ]"
HTH & Greetings from Bremen,
Daniel Krügler
As a matter of fact:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32997
You probably meant 7.1.3/3, didn't you? :)
> "In a given scope, a typedef specifier shall not be
> used to redefine the name of any type declared in
> that scope to refer to a different type. [ Example:
> class complex { / ... / };
> typedef int complex; // error: redefinition
> —end example ]"
On the other hand, these are fine:
// object
struct A { };
int A;
// function
struct A { };
int A();
// enumerator
struct A { };
enum { A };
as shown in 9.1/2:
<blockquote>
If a class name is declared in a scope where an object, function,
or enumerator of the same name is also declared, then when both
declarations are in scope, the class can be referred to only using
an elaborated-type-specifier (3.4.4). [Example:
struct stat {
// ...
};
stat gstat; // use plain stat to
// define variable
int stat(struct stat*); // redeclare stat as function
void f()
{
struct stat* ps; // struct prefix needed
// to name struct stat
// ...
stat(ps); // call stat()
// ...
}
—end example]
</blockquote>
--
Seungbeom Kim