vendredi 31 juillet 2015

Semantic errors with overload resolution for init-list-as-function-argument and templates

I've configured Eclipse CDT for C++11 use in its continual build process, but certain expressions are still causing semantic errors even though they compile properly using g++ 4.9.2 and clang++ 3.8.0. Namely, braced init lists supplied as function arguments are not matched to the arguments' corresponding std::initializer_list constructors and the right version of LLVM's cast function is not matched to its supplied arguments either. Is Eclipse CDT using an older, internal parser that doesn't support such C++11 functionality rather than delegating to the more modern external GCC toolchain, which it does detect?

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"

using namespace llvm;

// i32 @myFunc1(i32, i32), i32 @myFunc2(i32, i32)
SmallVector<Function*, 2> getMyFuncs(Module& M) {
  Type* i32 = Type::getInt32Ty(M.getContext());

  // error #1 reported
  FunctionType* FT = FunctionType::get(i32, {i32, i32}, false); 

 // error #2 reported
  Function* F1 = cast<Function>(M.getOrInsertFunction("myFunc1", FT));

  // no error with implicit matching of ArrayRef(const std::initializer_list<T>&) here
  ArrayRef<Type*> ArgTypes = {i32, i32};
  FT = FunctionType::get(i32, ArgTypes, false);

  // error #2 reported
  Function* F2 = cast<Function>(M.getOrInsertFunction("myFunc2", FT));

   // no error with implicit matching of SmallVector(std::initializer_list<T>) here
  return {F1, F2};
}

Error #1

Invalid arguments '
Candidates are:
llvm::FunctionType * get(llvm::Type *, llvm::ArrayRef, bool)
llvm::FunctionType * get(llvm::Type *, bool)

Error #2

Invalid arguments '
Candidates are:
llvm::cast_retty<#0,#1 *>::ret_type cast(#1 *) std::enable_if::ret_type>::type cast(const #1 &)
llvm::cast_retty<#0,#1>::ret_type cast(#1 &)
'

Aucun commentaire:

Enregistrer un commentaire