[llvm-bugs] [Bug 25348] New: C++ parse error on complex function call template expression

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 29 13:50:32 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=25348

            Bug ID: 25348
           Summary: C++ parse error on complex function call template
                    expression
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mtanski at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

I've recently tried building an application that we have using a new version of
Clang 3.7. Clang throws an error for a complex template expression for code
that g++ is able to compile. I tried to reduce this further (function instead
of FindKeyValueOp class) but that case works.

mtanski at ltsvm:~/petabucket$ cat test.cpp 
#include <cstdint>
#include <vector>

enum DataType {
        UINT32,
        STRING,
};

template <DataType DT>
struct TypeTraits
{ };

template <>
struct TypeTraits<DataType::UINT32>
{
        typedef uint32_t CppType;
};

struct Column
{
        template <DataType DT>
        typename TypeTraits<DT>::CppType* typed_data() {
                typedef typename TypeTraits<DT>::CppType CppType;
                return static_cast<CppType*>(ptr);
        }

private:
        DataType type;
        void* ptr;
};

struct Block {
        Column& column(int pos) { 
                return columns.at(pos);
        }

private:
        std::vector<Column> columns;
};

template <DataType Key, DataType Value>
struct FindKeyValueOp
{
        typedef typename TypeTraits<Key>::CppType* KeyPtr;
        typedef typename TypeTraits<Value>::CppType* DataPtr;

        FindKeyValueOp(Block& b) : parent(b) { }

        DataPtr FindKeyValue(KeyPtr key) {
                KeyPtr keys = parent.column(0).typed_data<Key>();
                DataPtr values = parent.column(1).typed_data<Value>();

                for (unsigned i = 0; keys + i != nullptr; i++) {
                        if (keys[i] == *key) {
                                return values + i;
                        } 
                }

                return nullptr;
        }
private:
        Block& parent;
};


int main() {
        Block block;
        auto op = FindKeyValueOp<DataType::UINT32,DataType::UINT32>(block);

        uint32_t key = 15;
        auto result = op.FindKeyValue(&key);

        return 0;
}
mtanski at ltsvm:~/petabucket$ clang++-3.7 -std=c++14 test.cpp 
test.cpp:50:50: error: expected expression
                KeyPtr keys = parent.column(0).typed_data<Key>();
                                                               ^
test.cpp:51:55: error: expected expression
                DataPtr values = parent.column(1).typed_data<Value>();
                                                                    ^
2 errors generated.
mtanski at ltsvm:~/petabucket$ g++-4.9 -std=c++14 test.cpp 
mtanski at ltsvm:~/petabucket$

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151029/553b9fc0/attachment-0001.html>


More information about the llvm-bugs mailing list