llvm / llvm-project

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

Regression where default template type parameters no longer reported #31886

Open llvmbot opened 7 years ago

llvmbot commented 7 years ago
Bugzilla Link 32539
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @emilio,@froydnj

Extended Description

Given this test case with a template definition using a default template type parameter:

template <typename T, typename U = int>
struct Foo {
    T t;
    U u;
};

static Foo<bool> bar;

In libclang 3.9, I get a cursor for bar's template instantiation like this:

(
 kind = StructDecl
 spelling = "Foo"
 location = ./tests/headers/default-template-parameter.hpp:2:8
 is-definition? true
 is-declaration? true
 is-inlined-function? false
 usr = "c:@S@Foo>#b#I"
 number-of-template-args = 2

 specialized.kind = ClassTemplate
 specialized.spelling = "Foo"
 specialized.location = ./tests/headers/default-template-parameter.hpp:2:8
 specialized.is-definition? true
 specialized.is-declaration? true
 specialized.is-inlined-function? false
 specialized.template-kind = StructDecl
 specialized.usr = "c:@ST>2#T#T@Foo"

 type.kind = Record
 type.cconv = 100
 type.spelling = "Foo<bool, int>"
 type.number-of-template-args = 2
 type.is-variadic? false
)

Then, using clang_Type_getNumTemplateArguments and clang_Type_getTemplateArgumentAsType, I get these template arguments:

Type(spelling: bool, kind: Bool)
Type(spelling: int, kind: Int)

In contrast, with libclang >= 4.0, I get only the explicit template argument, not the default type:

Type(spelling: bool, kind: Bool)

Here is the result of bisection on the git monorepo:

1cd3d77b9a8e18878a1654eb14053732b616b073 is the first bad commit
commit 1cd3d77b9a8e18878a1654eb14053732b616b073
Author: Argyrios Kyrtzidis <akyrtzi@gmail.com>
Date:   Tue Nov 15 20:51:46 2016 +0000

    [libclang] Generalize clang_getNumTemplateArguments and clang_getTemplateArgumentAsType to other kind of specializations.

    Patch by Emilio Cobos Álvarez!
    https://reviews.llvm.org/D26663
emilio commented 7 years ago

llvm/llvm-bugzilla-archive#32794

froydnj commented 7 years ago

To whomever it concerns: Is it possible for this regression fix (assuming the patch is accepted) to be included in a 4.X point release?

Follow instructions in http://lists.llvm.org/pipermail/llvm-dev/2017-March/111530.html

llvmbot commented 7 years ago

To whomever it concerns: Is it possible for this regression fix (assuming the patch is accepted) to be included in a 4.X point release?

Thanks!

emilio commented 7 years ago

Patch at https://reviews.llvm.org/D31732

emilio commented 7 years ago

I think I have a potential fix for this, building right now...