[cfe-dev] 3.8/3.9 SVN: Compile failure with enum and ternary operator
Peter Klotz via cfe-dev
cfe-dev at lists.llvm.org
Sun Jul 10 23:13:54 PDT 2016
Hi clang developers
clang 3.8 and 3.9 SVN fails to compile the C++ program below.
I already reported the bug via LLVM Bugzilla (
https://llvm.org/bugs/show_bug.cgi?id=28425) but got no response.
-------------------------------------
enum PermissionTypePk { PT_GLOBAL };
struct PermissionType
{
static PermissionType getPermissionType() { return PermissionType(); }
PermissionType() : m_pk(PT_GLOBAL) {}
const PermissionTypePk m_pk; // --> removing "const" makes the program
compile
};
int main()
{
const PermissionTypePk permissionTypePk = true ?
PermissionType::getPermissionType().m_pk : PT_GLOBAL;
return 0;
}
-------------------------------------
[user at host test]$ clang++ -Wall -Wextra -c clang_error.cpp
clang_error.cpp:11:28: error: cannot initialize a variable of type 'const
PermissionTypePk' with an rvalue of type 'int'
const PermissionTypePk permissionTypePk = true ?
PermissionType::getPermissionType().m_pk : PT_GLOBAL;
^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Removing "const" from member "m_pk" makes the program compile.
gcc 6 compiles both versions, with and without "const".
Regards, Peter.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160711/38cf4673/attachment.html>
More information about the cfe-dev
mailing list