C++ 在g++;但不是叮当作响++;

C++ 在g++;但不是叮当作响++;,c++,for-loop,c++11,clang,C++,For Loop,C++11,Clang,以下基于范围的代码段在g++4.6.1中编译良好,但在oneiric amd64上的clang++版本3.1(trunk 151577)中编译不好 一个非常基本的基于范围的for(例如std::vector)似乎可以正常工作,所以我自己的枚举实现出现了一些问题 我正在寻找一份精神检查或解决办法。 如果有人有一个工作范围为基础的叮当++是高兴的,这将是了不起的 template< typename E > class Enum { public: Enum() : m_e( E

以下基于范围的代码段在g++4.6.1中编译良好,但在oneiric amd64上的clang++版本3.1(trunk 151577)中编译不好

一个非常基本的基于范围的for(例如std::vector)似乎可以正常工作,所以我自己的枚举实现出现了一些问题

我正在寻找一份精神检查或解决办法。

如果有人有一个工作范围为基础的叮当++是高兴的,这将是了不起的

template< typename E >
class Enum
{
public:
    Enum() : m_e( E::Last ) { }
    Enum( E t ) : m_e( t ) { }
    E operator()() const
    {
        return m_e;
    }

public: 
    class Iterator
    {
    public:
        Iterator( int val ) : m_val( val )    { }
        E operator*( void ) const
        {
            return (E) m_val;
        }
        void operator++( void )
        {
            ++m_val;
        }
        bool operator!=( Iterator rhs ) const
        {
            return m_val != rhs.m_val;
        }
    private:
        int  m_val;
    };
private:
    E m_e;
};

enum class eCOLORS
{
    kBLUE=0, kGREEN, kRED, kPURPLE,
    First=kBLUE, Last=kPURPLE
};

Enum<eCOLORS>::Iterator begin(const Enum<eCOLORS>& b)
{
    return Enum<eCOLORS>::Iterator( (int)(eCOLORS::First ));
}

Enum<eCOLORS>::Iterator end(const Enum<eCOLORS>& b)
{
    return Enum<eCOLORS>::Iterator( (int)(eCOLORS::Last ));
}

int main()
{
    Enum<eCOLORS> e; 
    // for( const auto x : Enum<eCOLORS>() )
    for( auto it=begin(e); 
        it!=end(e); ++it )
    {

    }
}
模板
类枚举
{
公众:
Enum():m_e(e::Last){
枚举(et):m_E(t){}
E运算符()()常量
{
返回m_e;
}
公众:
类迭代器
{
公众:
迭代器(int-val):m_-val(val){}
E运算符*(无效)常量
{
返回(E)mu val;
}
void运算符++(void)
{
++穆瓦尔;
}
布尔运算符!=(迭代器rhs)常量
{
返回m_val!=rhs.m_val;
}
私人:
国际货币基金组织;
};
私人:
E m_E;
};
枚举类生态色
{
kBLUE=0,kGREEN,kRED,kPURPLE,
第一个=kBLUE,最后一个=kPURPLE
};
枚举::迭代器开始(常量枚举(&b)
{
返回枚举::迭代器((int)(eCOLORS::First));
}
枚举::迭代器结束(常量枚举(&b)
{
返回枚举::迭代器((int)(eCOLORS::Last));
}
int main()
{
枚举e;
//对于(常量自动x:Enum())
对于(自动),it=开始(e);
它!=结束(e);++它)
{
}
}
下面列出了错误

clang++ -g -std=c++0x \
    sandbox.cpp -o sandbox

clang: /mnt/home/foobar/src/llvm/tools/clang/lib/AST/Decl.cpp:1001: bool clang::NamedDecl::isCXXInstanceMember() const: Assertion `isCXXClassMember() && "checking whether non-member is instance member"' failed.
0  clang           0x0000000001aecc4f
1  clang           0x0000000001aed179
2  libpthread.so.0 0x00002aeeaeda1060
3  libc.so.6       0x00002aeeaf98b3a5 gsignal + 53
4  libc.so.6       0x00002aeeaf98eb0b abort + 379
5  libc.so.6       0x00002aeeaf983d4d __assert_fail + 221
6  clang           0x0000000000ed8f9e clang::NamedDecl::isCXXInstanceMember() const + 174
7  clang           0x0000000000a51095 clang::Sema::CheckQualifiedMemberReference(clang::Expr*, clang::QualType, clang::CXXScopeSpec const&, clang::LookupResult const&) + 213
8  clang           0x0000000000a55520 clang::Sema::BuildMemberReferenceExpr(clang::Expr*, clang::QualType, clang::SourceLocation, bool, clang::CXXScopeSpec const&, clang::SourceLocation, clang::NamedDecl*, clang::LookupResult&, clang::TemplateArgumentListInfo const*, bool) + 672
9  clang           0x0000000000a518d4 clang::Sema::BuildMemberReferenceExpr(clang::Expr*, clang::QualType, clang::SourceLocation, bool, clang::CXXScopeSpec&, clang::SourceLocation, clang::NamedDecl*, clang::DeclarationNameInfo const&, clang::TemplateArgumentListInfo const*) + 772
10 clang           0x0000000000b50378
11 clang           0x0000000000b58a19
12 clang           0x0000000000b56362
13 clang           0x0000000000b4e87b clang::Sema::SubstExpr(clang::Expr*, clang::MultiLevelTemplateArgumentList const&) + 75
14 clang           0x0000000000b64a69 clang::Sema::SubstInitializer(clang::Expr*, clang::MultiLevelTemplateArgumentList const&, bool) + 169
15 clang           0x0000000000b6d57f clang::Sema::InstantiateMemInitializers(clang::CXXConstructorDecl*, clang::CXXConstructorDecl const*, clang::MultiLevelTemplateArgumentList const&) + 1135
16 clang           0x0000000000b6cb13 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool) + 2307
17 clang           0x0000000000b6dadd clang::Sema::PerformPendingInstantiations(bool) + 461
18 clang           0x00000000008e0bb3 clang::Sema::ActOnEndOfTranslationUnit() + 419
19 clang           0x00000000008757d0 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 112
20 clang           0x00000000008727c6 clang::ParseAST(clang::Sema&, bool) + 326
21 clang           0x000000000075623e clang::CodeGenAction::ExecuteAction() + 958
22 clang           0x0000000000612f3d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 957
23 clang           0x00000000005fb55a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3098
24 clang           0x00000000005f17ce cc1_main(char const**, char const**, char const*, void*) + 5918
25 clang           0x00000000005f7679 main + 729
26 libc.so.6       0x00002aeeaf97630d __libc_start_main + 237
27 clang           0x00000000005effe9
Stack dump:
0.  Program arguments: /usr/local/bin/clang -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name sandbox.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -g -resource-dir /usr/local/bin/../lib/clang/3.1 -I /home/kfeng/dev/pitbull/cpp/inc/ -I /home/kfeng/src/stlsoft/include/ -I /home/kfeng/src/gtest/include/ -I /home/kfeng/src/gmock/include/ -I /home/kfeng/src/pantheios/include/ -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++0x -fdeprecated-macro -fdebug-compilation-dir /home/kfeng/dev/pitbull/cpp/sbx -ferror-limit 19 -fmessage-length 181 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/sandbox-0nnyL0.o -x c++ sandbox.cpp 
1.  <eof> parser at end of file
2.  sandbox.cpp:5:2: instantiating function definition 'Enum'
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang: note: diagnostic msg: Please submit a bug report to http://llvm.org/bugs/ and include command line arguments and all diagnostic information.
clang: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/sandbox-Fp11tf.ii
clang: note: diagnostic msg: /tmp/sandbox-Fp11tf.sh
clang++-g-std=c++0x\
sandbox.cpp-o sandbox
clang:/mnt/home/foobar/src/llvm/tools/clang/lib/AST/Decl.cpp:1001:bool clang::namedecl::isCXXInstanceMember()常量:断言'isCXXClassMember()&&“检查非成员是否为实例成员”失败。
0叮当声0x0000000001aecc4f
1个叮当声0x0000000001aed179
2 libpthread.so.0 0x00002EEAEDA1600
3 libc.so.6 0x00002AEAF98B3A5 G信号+53
4 libc.so.6 0x00002AEAF98EB0B中止+379
5 libc.so.6 0x00002AEAF983D4D uu断言u失败+221
6 clang 0x0000000000ed8f9e clang::NamedDecl::ISC2InstanceMember()常量+174
7 clang 0x0000000000a51095 clang::Sema::CheckQualifiedMemberReference(clang::Expr*,clang::QualType,clang::CXXScopeSpec const&,clang::LookupResult const&)+213
8 clang 0x0000000000a55520 clang::Sema::BuildMemberReferenceExpr(clang::Expr*,clang::QualType,clang::SourceLocation,bool,clang::cxscopespec const&,clang::SourceLocation,clang::namedecl*,clang::LookupResult&,clang::TemplateArgumentListInfo const*,bool)+672
9 clang 0x0000000000a518d4 clang::Sema::BuildMemberReferenceExpr(clang::Expr*,clang::QualType,clang::SourceLocation,bool,clang::cxscopespec&,clang::SourceLocation,clang::namedecl*,clang::declarationnameinfoconst&,clang::templateargumentlistinfoconst*)+772
10克拉0x0000000000b50378
11铿锵0x0000000000b58a19
12响0x0000000000b56362
13 clang 0x0000000000b4e87b clang::Sema::substepr(clang::Expr*,clang::MultiLevelTemplateArgumentList常量&)+75
14 clang 0x0000000000b64a69 clang::Sema::子初始值设定项(clang::Expr*,clang::MultiLevelTemplateArgumentList const&,bool)+169
15 clang 0x0000000000b6d57f clang::Sema::实例化最小化器(clang::CXXConstructorDecl*,clang::CXXConstructorDecl const*,clang::多级模板参数列表const&+1135
16 clang 0x0000000000b6cb13 clang::Sema::InstanceFunctionDefinition(clang::SourceLocation,clang::FunctionDecl*,bool,bool)+2307
17铿锵0x0000000000b6dadd铿锵::语义::性能安装(bool)+461
18 clang 0x00000000008e0bb3 clang::Sema::ActOnEndOfTranslationUnit()+419
19铿锵0x00000000008757d0铿锵::Parser::ParseTopLevelDecl(铿锵::OpaquePtr&)+112
20铿锵0x00000000008727c6铿锵::ParseAST(铿锵::Sema&,bool)+326
21 clang 0x000000000075623e clang::CodeGenAction::ExecuteAction()+958
22铿锵0x0000000000612f3d铿锵::编译器立场::执行动作(铿锵::前端动作&)+957
23 clang 0x00000000005fb55a clang::ExecuteCompilerInvocation(clang::CompilerInstance*)+3098
24个字符0x00000000005f17ce cc1_main(字符常量**,字符常量**,字符常量*,无效*)+5918
25克拉0x00000000005f7679干管+729
26 libc.so.6 0x00002AEAF97630D\u libc\u start\u main+237
27叮当声0x000000000059
堆栈转储:
0程序参数:/usr/local/bin/clang-cc1-triple x86_64-unknown-linux-gnu-emit obj-mrelax all-disable free-main file name sandbox.cpp-mrelocation model static-mdisable fp-elim-masm verbose-mconstructor alias-munwind tables-target cpu x86-64-momit叶帧指针-g-resource dir/usr/local/bin/./lib/clang/3.1-I/home/kfeng/dev/pitbull/cpp/inc/-I/home/kfeng/src/gtest/include/-I/home/kfeng/src/gmock/include/-I/home/kfeng/src/pantheios/include/-fmodule缓存路径/var/tmp/clang模块缓存-内部isystem/usr/lib/gcc/x86\u 64-linux-gnu/4.6/../../../../../include/c++/4.6-内部isystem/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../../../include/c++/4.6/x86_64-linux-gnu-内部isystem/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../../include/c++/4.6/backward internal isystem/usr/local/include-internal isystem/usr/local/bin/../lib/clang/3.1/include-internal externc-externc-isystem/usr/usr/include/usr/x86-linux-gnu/include-内部外部isystem/usr/include-std=c++0x-fdebug编译目录/home/kfeng/dev/pitbull/cpp/sbx-ferror限制19-fmessage length 181-mstackreallign-fgnu运行时-fobjc运行时有弧-fobjc运行时有弱-fobjc脆弱abi-fcxx异常-feexceptions-fddiagnostics show选项-fcolor diagnostics-o/TMP/StObx-0nnL0.O-XC++ C++ StBoBOX.CPP
1.文件末尾的解析器
% clang --version
clang version 3.0 (tags/RELEASE_30/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
% clang++ -o test test.cc -std=c++0x
%