[llvm-bugs] [Bug 42381] New: After formatting done by the clang-format utility, the source code of the class ++ template class does not compile

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 25 01:54:41 PDT 2019


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

            Bug ID: 42381
           Summary: After formatting done by the clang-format utility, the
                    source code of the class ++ template class does not
                    compile
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rumgot at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

// OS Ubuntu 18.04 x64
// Compiler g++ 7.4.0 (compilation runs in c++11 mode)
// Tested on standard styles that are part of the сlang-format utility (LLVM,
Google, Chromium, Mozilla, WebKit)

// There is code on C++

#include <iostream>
#include <set>

template <typename T>
class Point;

template <typename T>
std::ostream &operator<< (std::ostream &os, const Point<T> &point);

template <typename T>
bool operator< (const Point<T> &point, const Point<T> &otherPoint);

template <typename T>
class Point {
   public:
    Point() : x_(0), y_(0) {}
    Point(const T &x, const T &y) : x_(x), y_(y) {}

    bool isPointsInHorLine(const Point<T> &other) const {
        return y_ == other.y_;
    }

    friend std::ostream &operator<< <>(std::ostream &os, const Point<T>
&point);

    // Pay attention to this line (Before formatting utility сlang-format):
    // friend bool operator< <>(const Point<T> &point, const Point<T>
&otherPoint);

    // After formatting with the Klangformat utility, this line will be (as
such, the string is not compiled):
    friend bool operator<<>(const Point<T> &point, const Point<T> &otherPoint);

   private:
    T x_;
    T y_;
};

template <typename T>
std::ostream &operator<< (std::ostream &os, const Point<T> &point) {
    os << "Point(" << point.x_ << ", " << point.y_ << ")";
    return os;
}



template <typename T>
bool operator< (const Point<T> &point, const Point<T> &otherPoint) {
    return point.isPointsInHorLine(otherPoint) ? point.x_ < otherPoint.x_
                                               : point.y_ < otherPoint.y_;
}

int main(int argc, char *argv[]) {
    Point<int> point(5, 5);   

    std::cout << point << std::endl;

    return 0;
}

-- 
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/20190625/0adf4723/attachment.html>


More information about the llvm-bugs mailing list