llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.51k stars 11.79k forks source link

clang incorrectly rejects member function because of template substitution failure (out-of-line definition) #15860

Open llvmbot opened 11 years ago

llvmbot commented 11 years ago
Bugzilla Link 15488
Version trunk
OS Linux
Attachments Reduced testcase.
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

In the attached reduced testcase, clang incorrectly gives me the compile error:

bug_clang_template_deduction.cpp:46:18: error: out-of-line definition of 'bar' does not match any declaration in 'derived' void derived::bar(Matrix<baseclass::n*baseclass::n>& F_x)

clang fails because of the combination of the following four aspects:

  • the class "derived" and its base class "base" are templates
  • the template parameter of the method is the result of a multiplication
  • the factors are static const int's defined in the base class
  • the operator * is overloaded for an unrelated data type (a simplified form of std::complex) that can be implicitly constructed from int.

Removing any of these four aspects makes the code compile. The code is valid afaict.

Tested on clang 3.2 and trunk: clang version 3.3 (trunk 176804) Target: x86_64-unknown-linux-gnu Thread model: posix

llvmbot commented 7 years ago

Using clang3.8, bug_clang_template_deduction.cpp compiles for me:

make showbug /home/evansl/dwnlds/llvm/3.8/prebuilt/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang++ -c -O0 -stdlib=libc++ -std=c++14 -ftemplate-backtrace-limit=0 -fdiagnostics-show-template-tree -fno-elide-type -fmacro-backtrace-limit=0 --version clang version 3.8.0 (tags/RELEASE_380/final) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/evansl/dwnlds/llvm/3.8/prebuilt/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04/bin uname -a Linux lje-OptiPlex-9020 4.4.0-57-generic #​78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux /home/evansl/dwnlds/llvm/3.8/prebuilt/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-14.04/bin/clang++ -c -O0 -stdlib=libc++ -std=c++14 -ftemplate-backtrace-limit=0 -fdiagnostics-show-template-tree -fno-elide-type -fmacro-backtrace-limit=0 -c bug_clang_template_deduction.cpp

Compilation finished at Sun Jan 8 01:52:59

So, apparently, the problem Martin was having was different than my problem.

I guess I should open separate bug report?

-regards, Larry

llvmbot commented 7 years ago

showbug.imk output This output shows 3 compile runs with varying values the the macros. The last run should compile OK; however, it produces the incorrect error message about out-of-line definition not matching anything in the template class.

llvmbot commented 7 years ago

makefile snippet Use this makefile snippet (with your definition of COMPILE.HOW) to reproduce the showbug.out attachment.

llvmbot commented 7 years ago

test case

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 11 years ago

Thanks, interesting testcase. I expect the issue is that when parsing the declaration of the template, we create a simple multiplication node (because unqualified lookup finds no 'operator*') for the dependent multiplication expression, but when parsing the definition, we create an overloaded operator expression to store the result of unresolved name lookup -- and we (incorrectly, as far as I can tell) believe this difference makes the function template signature different.