[llvm-bugs] [Bug 32208] New: clang format misinterprets less-than-operator inside template declaration with enable_if

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 10 01:03:45 PST 2017


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

            Bug ID: 32208
           Summary: clang format misinterprets less-than-operator inside
                    template declaration with enable_if
           Product: clang
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: per.ola.nilsson at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

clang-format seems to misinterpret less-than operator inside enable_if. First
manually formatted code, where enable_if aligns between the two functions:

$ cat for_each_tuple_indexed.h 
#pragma once
#include <tuple>
#include <utility>

template <std::size_t I = 0, typename FuncT, typename... Tp>
inline typename std::enable_if<I == sizeof...(Tp), void>::type
for_each_indexed(
    const std::tuple<Tp...> &,
    FuncT &&) { // recursion terminal case, I is equal to length of tuple
}

template <std::size_t I = 0, typename FuncT, typename... Tp>
inline typename std::enable_if<I < sizeof...(Tp), void>::type for_each_indexed(
    const std::tuple<Tp...> &t,
    FuncT &&f) {
  std::forward<FuncT>(f)(std::get<I>(t), I);
  for_each_indexed<I + 1, FuncT, Tp...>(t, std::forward<FuncT>(f));
}

====== 

$ clang-format-4.0 -style=llvm  for_each_tuple_indexed.h 
#pragma once
#include <tuple>
#include <utility>

template <std::size_t I = 0, typename FuncT, typename... Tp>
inline typename std::enable_if<I == sizeof...(Tp), void>::type
for_each_tuple_indexed(
    const std::tuple<Tp...> &,
    FuncT &&) { // recursion terminal case, I is equal to length of tuple
}

template <std::size_t I = 0, typename FuncT, typename... Tp>
    inline typename std::enable_if <
    I<sizeof...(Tp), void>::type
    for_each_tuple_indexed(const std::tuple<Tp...> &t, FuncT &&f) {
  std::forward<FuncT>(f)(std::get<I>(t), I);
  for_each_indexed<I + 1, FuncT, Tp...>(t, std::forward<FuncT>(f));
}

-- 
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/20170310/8b9b5116/attachment-0001.html>


More information about the llvm-bugs mailing list