Bug 16879 - variable declaration not allowed
Summary: variable declaration not allowed
Status: RESOLVED DUPLICATE of bug 11796
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: 3.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-04 18:32 UTC by Ben Horner
Modified: 2005-07-23 22:49 UTC (History)
1 user (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 Ben Horner 2004-08-04 18:32:46 UTC
I'm the following version of gcc (as reported by gcc_select)
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)

My system is (as reported by "About This Mac"):
Model:
PowerBook G4 17"
Operating system:
Mac OS X Version 10.3.4
Processor:
1 GHz PowerPC G4
1 MB L3 cache
Memory:
1 GB DDR SDRAM

gcc was configured / built / installed by the Mac developer tools install program.

the command line that triggers the bug is:
g++ main.cpp

compiler output (from g++ -v -save-temps main.cpp):
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)
 /usr/libexec/gcc/darwin/ppc/3.3/cc1plus -E -D__GNUG__=3 -quiet -v -D__GNUC__=3 
-D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=0 -D__APPLE_CC__=1495 -D__DYNAMIC__ 
main.cpp -fPIC -D__private_extern__=extern main.ii
ignoring nonexistent directory "/usr/ppc-darwin/include"
ignoring nonexistent directory "/Local/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/gcc/darwin/3.3/c++
 /usr/include/gcc/darwin/3.3/c++/ppc-darwin
 /usr/include/gcc/darwin/3.3/c++/backward
 /usr/local/include
 /usr/include/gcc/darwin/3.3
 /usr/include
End of search list.
Framework search starts here:
 /System/Library/Frameworks
 /Library/Frameworks
End of framework search list.
 /usr/libexec/gcc/darwin/ppc/3.3/cc1plus -fpreprocessed main.ii -fPIC -quiet -dumpbase main.cpp 
-auxbase main -version -D__private_extern__=extern -o main.s
GNU C++ version 3.3 20030304 (Apple Computer, Inc. build 1495) (ppc-darwin)
        compiled by GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=131072
main.cpp: In function `int main()':
main.cpp:28: error: variable declaration is not allowed here

my actual source code (which contains no includes or anything, but does contain examples):
template <typename T>
class ParameterMember{
        private:
                T m_T_inst;
        public:
                ParameterMember(const T& T_inst): m_T_inst(T_inst){}
};
typedef ParameterMember<int> PrimitiveMember;
typedef ParameterMember<PrimitiveMember> InstanceMember;

int main(){
//----------------------------------------------------------------------------
        // this doesn't compile; "error: variable declaration is not allowed here"
        ParameterMember<InstanceMember> x(InstanceMember(PrimitiveMember(10)));
//----------------------------------------------------------------------------
        // why is variable declaration not allowed above?
//----------------------------------------------------------------------------
        // this compiles
        // ParameterMember<IntstanceMember> is constructed as a temporary
//      ParameterMember<InstanceMember>(InstanceMember(PrimitiveMember(10)));
//----------------------------------------------------------------------------
        // this compiles
        // default assignment of temporary to declared variable... (initialization?)
//      ParameterMember<InstanceMember> x = 
ParameterMember<InstanceMember>(InstanceMember(PrimitiveMember(10)));
//----------------------------------------------------------------------------
        // this compiles
        // ParameterMember<InstanceMember> is constructed from a temporary InstanceMember
//      PrimitiveMember prm(10);
//      ParameterMember<InstanceMember> pm1(InstanceMember(prm));
//----------------------------------------------------------------------------
        // this compiles
        // IntanceMember is constructed from a temporary PrimitiveMember
//      InstanceMember im(PrimitiveMember(10));
//      ParameterMember<InstanceMember> pm2(im);
//----------------------------------------------------------------------------
}
Comment 1 Andrew Pinski 2004-08-04 18:36:04 UTC

*** This bug has been marked as a duplicate of 11796 ***
Comment 2 Wolfgang Bangerth 2004-08-04 19:43:57 UTC
Note that this is actually not exactly the same bug as in PR 11796, but 
falls into the same class of things that were fixed in gcc 3.4. You 
can learn more about this in the release notes for gcc3.4, to be found 
somewhere on http://gcc.gnu.org. 
 
W. 
Comment 3 Andrew Pinski 2004-08-04 20:47:15 UTC
Actually it is the same, as "InstanceMember(PrimitiveMember (x))" is the same as int(int(x)).