Re: Scoped enum question
On Wednesday, June 12, 2013 6:01:23 PM UTC, Luca Risolia wrote:
Do you mean something like this?
Looks interesting.
class cmw_user_input_data_member_flags {
public:
enum E : int16_t {
headers = 0x1,
middlefile = 0x2,
choices = 0x4
};
constexpr cmw_user_input_data_member_flags() noexcept {};
constexpr cmw_user_input_data_member_flags(E v) noexcept : val{v} {};
cmw_user_input_data_member_flags(const cmw_user_input_data_member_flag=
s& o)
noexcept : val{o.val} {};
cmw_user_input_data_member_flags& operator=(E v) noexcept
{val = v; return *this;};
cmw_user_input_data_member_flags&
operator=(cmw_user_input_data_member_flags& o) noexcept
{val = o.val; return *this;};
// other operators: &, |, etc...
operator E() const noexcept {return val;};
protected:
E val{};
Are the {} some sort of initialization?
I tried changing that to
E val{0};
and clang croaked:
ew2.cc:27:11: error: cannot initialize a member subobject of type
'cmw_user_input_data_member_flags::E' with an rvalue of type 'int'
E val{0};
^
0 libLLVM-3.2.so 0x00007fc35ddd90bf
1 libLLVM-3.2.so 0x00007fc35ddd9529
2 libpthread.so.0 0x00007fc35d0811e0
3 clang 0x0000000000f3ade0
4 clang 0x0000000000f551ec
5 clang 0x0000000000f55ab5
6 clang 0x0000000000f562c0 clang::Expr::isPotentialConstantExpr(=
clang::FunctionDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLo=
cation, clang::PartialDiagnostic> >&) + 1200
7 clang 0x00000000009cf02d clang::Sema::CheckConstexprFunctionBo=
dy(clang::FunctionDecl const*, clang::Stmt*) + 1005
8 clang 0x000000000098b7b7 clang::Sema::ActOnFinishFunctionBody(=
clang::Decl*, clang::Stmt*, bool) + 1527
9 clang 0x00000000008e3306 clang::Parser::ParseFunctionStatement=
Body(clang::Decl*, clang::Parser::ParseScope&) + 182
10 clang 0x00000000008f13da clang::Parser::ParseLexedMethodDef(cl=
ang::Parser::LexedMethod&) + 490
11 clang 0x00000000008f1170 clang::Parser::ParseLexedMethodDefs(c=
lang::Parser::ParsingClass&) + 128
12 clang 0x00000000008a45e4 clang::Parser::ParseCXXMemberSpecific=
ation(clang::SourceLocation, unsigned int, clang::Decl*) + 1108
13 clang 0x00000000008a5c57 clang::Parser::ParseClassSpecifier(cl=
ang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser=
::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::D=
eclSpecContext) + 3127
14 clang 0x0000000000893360 clang::Parser::ParseDeclarationSpecif=
iers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::Acc=
essSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttr=
List*) + 1888
15 clang 0x00000000008814cf clang::Parser::ParseDeclOrFunctionDef=
Internal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&=
, clang::AccessSpecifier) + 79
16 clang 0x0000000000881d21
17 clang 0x0000000000881d4f clang::Parser::ParseDeclarationOrFunc=
tionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDec=
lSpec*, clang::AccessSpecifier) + 31
18 clang 0x00000000008837a7 clang::Parser::ParseExternalDeclarati=
on(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 10=
3
19 clang 0x000000000088424f clang::Parser::ParseTopLevelDecl(clan=
g::OpaquePtr<clang::DeclGroupRef>&) + 191
20 clang 0x000000000087ca7e clang::ParseAST(clang::Sema&, bool, b=
ool) + 270
21 clang 0x0000000000613b11 clang::FrontendAction::Execute() + 97
22 clang 0x00000000005fa23a clang::CompilerInstance::ExecuteActio=
n(clang::FrontendAction&) + 282
23 clang 0x00000000005e3362 clang::ExecuteCompilerInvocation(clan=
g::CompilerInstance*) + 1378
24 clang 0x00000000005de388 cc1_main(char const**, char const**, =
char const*, void*) + 1160
25 clang 0x00000000005dd2ab main + 7259
26 libc.so.6 0x00007fc35c7cea15 __libc_start_main + 245
27 clang 0x00000000005ddd89
Stack dump:
0. Program arguments: /usr/bin/clang -cc1 -triple x86_64-unknown-linux-gnu =
-emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name =
new2.cc -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verb=
ose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-=
64 -target-linker-version 2.23.1 -momit-leaf-frame-pointer -resource-dir /u=
sr/bin/../lib/clang/3.2 -fmodule-cache-path /var/tmp/clang-module-cache -in=
ternal-isystem /usr/lib64/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../in=
clude/c++/4.7.2 -internal-isystem /usr/lib64/gcc/x86_64-unknown-linux-gnu/4=
..7.2/../../../../include/c++/4.7.2/x86_64-unknown-linux-gnu -internal-isyst=
em /usr/lib64/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.=
7.2/backward -internal-isystem /usr/local/include -internal-isystem /usr/bi=
n/../lib/clang/3.2/include -internal-externc-isystem /include -internal-ext=
ernc-isystem /usr/include -std=c++0x -fdeprecated-macro -fdebug-compilati=
on-dir /srv/http/misc -ferror-limit 19 -fmessage-length 91 -mstackrealign -=
fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option=
-fcolor-diagnostics -o /tmp/new2-ciRU2v.o -x c++ new2.cc
1. new2.cc:30:2: current parser token ';'
2. new2.cc:3:1: parsing struct/union/class body 'cmw_user_input_data_member=
_flags'
3. new2.cc:10:59: parsing function body 'cmw_user_input_data_member_flags'
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see in=
vocation)
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
clang: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/=
bugs/ and include the crash backtrace, preprocessed source, and associated =
run script.
clang: note: diagnostic msg:
private:
//operator long int(); // eventually
};