[llvm-bugs] [Bug 34624] New: A template-friend bug of bound friend templates

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 15 06:49:07 PDT 2017


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

            Bug ID: 34624
           Summary: A template-friend bug of bound friend templates
           Product: clang
           Version: 4.0
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: question123446 at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

First: 
$ clang++ -v
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /usr/local/bin

********************************

I write code as below:

#include <iostream>

using namespace std;

//template <typename T>
//class A;
//
//template <typename T>
//bool operator == (const A<T> & a1, const A<T> & a2);

template <typename T>
class A {
        friend bool operator ==<> (const A & a1, const A & a2); 
};

template <typename T>
bool operator == (const A<T> & a1, const A<T> & a2)
{
        return true;
}

int main(int argc, char *argv[]) 
{
        A<int> a1, a2;
        cout << (a1 == a2) << endl;

//      if (a1 == a2) {
//              cout << "......" << endl;
//      }
}

I used `clang++ -std=c++11 bound\ friend\ templates.cc -o bound\ friend\
templates`.
This can pass the compiler. However, C++ standards don't allow this. We'd use a
declaration to declare the class and the operator == function, as the
annotation above. This is the first bug.

Besides, when I use `./` to run this program, it's interesting to see the
standard output shows nothing instead of `1`. So I cancelled the annotation in
`main` function. Then, clang++ turns to bug.

*************** clang++ Error message *********************

0  clang-4.0                0x000000010f432e1b
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  clang-4.0                0x000000010f4323b3 llvm::sys::RunSignalHandlers() +
83
2  clang-4.0                0x000000010f43323a SignalHandler(int) + 195
3  libsystem_platform.dylib 0x00007fff9ebd0b3a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fdd13c1fc10 _sigtramp + 1963258096
5  clang-4.0                0x000000010f6033f7 (anonymous
namespace)::ScalarExprEmitter::Visit(clang::Expr*) + 43
6  clang-4.0                0x000000010f6033c6
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) + 50
7  clang-4.0                0x000000010f5dcfb1
clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) + 295
8  clang-4.0                0x000000010f69193f
clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(clang::Expr const*,
llvm::BasicBlock*, llvm::BasicBlock*, unsigned long long) + 1857
9  clang-4.0                0x000000010f667440
clang::CodeGen::CodeGenFunction::EmitIfStmt(clang::IfStmt const&) + 416
10 clang-4.0                0x000000010f66c453
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot) + 83
11 clang-4.0                0x000000010f690498
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&,
clang::Stmt const*) + 88
12 clang-4.0                0x000000010f690a7c
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 684
13 clang-4.0                0x000000010f69cf22
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*) + 254
14 clang-4.0                0x000000010f69a77c
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) + 316
15 clang-4.0                0x000000010f69e29f
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 169
16 clang-4.0                0x000000010f6eabc9 (anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) + 125
17 clang-4.0                0x000000010f68acb6
clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 180
18 clang-4.0                0x000000010fd00861 clang::ParseAST(clang::Sema&,
bool, bool) + 319
19 clang-4.0                0x000000010f80374a clang::FrontendAction::Execute()
+ 76
20 clang-4.0                0x000000010f7d666b
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 605
21 clang-4.0                0x000000010f832398
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3448
22 clang-4.0                0x000000010e6a23b9 cc1_main(llvm::ArrayRef<char
const*>, char const*, void*) + 1337
23 clang-4.0                0x000000010e6a101a main + 8096
24 libdyld.dylib            0x00007fff9e9c1235 start + 1
25 libdyld.dylib            0x0000000000000036 start + 1633938946
Stack dump:
0.      Program arguments: /usr/local/Cellar/llvm/4.0.0/bin/clang-4.0 -cc1
-triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage
-Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free
-disable-llvm-verifier -discard-value-names -main-file-name Untitled 2.cpp
-mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim
-masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2
-dwarf-column-info -debugger-tuning=lldb -resource-dir
/usr/local/Cellar/llvm/4.0.0/bin/../lib/clang/4.0.0 -stdlib=libc++ -std=c++11
-fdeprecated-macro -fdebug-compilation-dir
/Users/zhengxiaolin/Documents/cpp/c++11/move -ferror-limit 19 -fmessage-length
101 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0
-fencode-extended-block-signature -fcxx-exceptions -fexceptions
-fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o
/var/folders/wc/0c_zn09x12s_y90ccmvjb6900000gn/T/Untitled 2-a27030.o -x c++
Untitled 2.cpp
1.      <eof> parser at end of file
2.      Untitled 2.cpp:22:5: LLVM IR generation of declaration 'main'
3.      Untitled 2.cpp:22:5: Generating code for declaration 'main'
clang-4.0: error: unable to execute command: Segmentation fault: 11
clang-4.0: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /usr/local/bin
clang-4.0: note: diagnostic msg: PLEASE submit a bug report to
http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and
associated run script.
clang-4.0: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-4.0: note: diagnostic msg:
/var/folders/wc/0c_zn09x12s_y90ccmvjb6900000gn/T/Untitled 2-44bbe2.cpp
clang-4.0: note: diagnostic msg:
/var/folders/wc/0c_zn09x12s_y90ccmvjb6900000gn/T/Untitled 2-44bbe2.sh
clang-4.0: note: diagnostic msg:
/var/folders/wc/0c_zn09x12s_y90ccmvjb6900000gn/T/Untitled 2-44bbe2.crash
clang-4.0: note: diagnostic msg:

********************

*************** clang++ Error message over ****************

At the first bug, I didn't write the declaration of the class and the operator
++ function. clang++ didn't give an error to me but g++ has:

*************** g++ Error message ***********************

Untitled 2.cpp: In instantiation of 'class A<int>':
Untitled 2.cpp:24:9:   required from here
Untitled 2.cpp:13:14: error: template-id 'operator==<>' for 'bool
operator==(const A<int>&, const A<int>&)' does not match any template
declaration
  friend bool operator ==<> (const A & a1, const A & a2);
              ^~~~~~~~~~~~~
In file included from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/locale_facets.h:48:0,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/basic_ios.h:37,
                 from /usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ios:44,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ostream:38,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/iostream:39,
                 from Untitled 2.cpp:1:
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/streambuf_iterator.h:204:5:
note: candidates are: template<class _CharT, class _Traits> bool
std::operator==(const std::istreambuf_iterator<_CharT, _Traits>&, const
std::istreambuf_iterator<_CharT, _Traits>&)
     operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
     ^~~~~~~~
In file included from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/ios_base.h:46:0,
                 from /usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ios:42,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ostream:38,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/iostream:39,
                 from Untitled 2.cpp:1:
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/system_error:303:3: note:      
          bool std::operator==(const std::error_condition&, const
std::error_condition&)
   operator==(const error_condition& __lhs,
   ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/system_error:296:3: note:      
          bool std::operator==(const std::error_condition&, const
std::error_code&)
   operator==(const error_condition& __lhs, const error_code& __rhs) noexcept
   ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/system_error:289:3: note:      
          bool std::operator==(const std::error_code&, const
std::error_condition&)
   operator==(const error_code& __lhs, const error_condition& __rhs) noexcept
   ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/system_error:284:3: note:      
          bool std::operator==(const std::error_code&, const std::error_code&)
   operator==(const error_code& __lhs, const error_code& __rhs) noexcept
   ^~~~~~~~
In file included from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/string:52:0,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/locale_classes.h:40,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/ios_base.h:41,
                 from /usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ios:42,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ostream:38,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/iostream:39,
                 from Untitled 2.cpp:1:
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/basic_string.h:5084:5:
note:                 template<class _CharT, class _Traits, class _Alloc> bool
std::operator==(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&,
const _CharT*)
     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/basic_string.h:5072:5:
note:                 template<class _CharT, class _Traits, class _Alloc> bool
std::operator==(const _CharT*, const std::__cxx11::basic_string<_CharT,
_Traits, _Alloc>&)
     operator==(const _CharT* __lhs,
     ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/basic_string.h:5058:5:
note:                 template<class _CharT> typename
__gnu_cxx::__enable_if<std::__is_char<_Tp>::__value, bool>::__type
std::operator==(const std::__cxx11::basic_string<_CharT>&, const
std::__cxx11::basic_string<_CharT>&)
     operator==(const basic_string<_CharT>& __lhs,
     ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/basic_string.h:5050:5:
note:                 template<class _CharT, class _Traits, class _Alloc> bool
std::operator==(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&,
const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
In file included from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/string:41:0,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/locale_classes.h:40,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/ios_base.h:41,
                 from /usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ios:42,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ostream:38,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/iostream:39,
                 from Untitled 2.cpp:1:
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/allocator.h:152:5: note:  
              template<class _Tp> bool std::operator==(const
std::allocator<_CharT>&, const std::allocator<_CharT>&)
     operator==(const allocator<_Tp>&, const allocator<_Tp>&)
     ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/allocator.h:146:5: note:  
              template<class _T1, class _T2> bool std::operator==(const
std::allocator<_CharT>&, const std::allocator<_T2>&)
     operator==(const allocator<_T1>&, const allocator<_T2>&)
     ^~~~~~~~
In file included from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/stl_algobase.h:67:0,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/char_traits.h:39,
                 from /usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ios:40,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ostream:38,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/iostream:39,
                 from Untitled 2.cpp:1:
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/stl_iterator.h:1119:5:
note:                 template<class _Iterator> bool std::operator==(const
std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
     operator==(const move_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/stl_iterator.h:1113:5:
note:                 template<class _IteratorL, class _IteratorR> bool
std::operator==(const std::move_iterator<_IteratorL>&, const
std::move_iterator<_IteratorR>&)
     operator==(const move_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/stl_iterator.h:349:5:
note:                 template<class _IteratorL, class _IteratorR> bool
std::operator==(const std::reverse_iterator<_Iterator>&, const
std::reverse_iterator<_IteratorR>&)
     operator==(const reverse_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/stl_iterator.h:292:5:
note:                 template<class _Iterator> bool std::operator==(const
std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
     operator==(const reverse_iterator<_Iterator>& __x,
     ^~~~~~~~
In file included from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/stl_algobase.h:64:0,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/char_traits.h:39,
                 from /usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ios:40,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ostream:38,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/iostream:39,
                 from Untitled 2.cpp:1:
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/stl_pair.h:431:5: note:   
             template<class _T1, class _T2> constexpr bool
std::operator==(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^~~~~~~~
In file included from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/iosfwd:40:0,
                 from /usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ios:38,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/ostream:38,
                 from
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/iostream:39,
                 from Untitled 2.cpp:1:
/usr/local/Cellar/gcc/6.3.0_1/include/c++/6.3.0/bits/postypes.h:216:5: note:   
             template<class _StateT> bool std::operator==(const
std::fpos<_StateT>&, const std::fpos<_StateT>&)
     operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
     ^~~~~~~~

****************** g++ Error message over ************************

These two bugs are what I met today.
Best regards,
Andy

-- 
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/20170915/ef00b495/attachment-0001.html>


More information about the llvm-bugs mailing list