Skip to content

Duplicate explicit template instantiation reports incorrect source location #14230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
llvmbot opened this issue Sep 17, 2012 · 4 comments
Open
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2012

Bugzilla Link 13858
Version trunk
OS All
Reporter LLVM Bugzilla Contributor

Extended Description

Sometimes the note for the "previous explicit instantiation" refers to an implicit instantiation instead of the explicit one. For example, take this as test.cpp:

template <typename T>
struct S {
};

void foo() {
    S<int>();
}

template struct S<int>;
template struct S<int>;

Actual Results:

$ clang -c test.cpp
test.cpp:10:17: error: duplicate explicit instantiation of 'S<int>'
template struct S<int>;
                ^
test.cpp:6:5: note: previous explicit instantiation is here
    S<int>();
    ^
1 error generated.

Expected results:

$ clang -c test.cpp
test.cpp:10:17: error: duplicate explicit instantiation of 'S<int>'
template struct S<int>;
                ^
test.cpp:9:17: note: previous explicit instantiation is here
template struct S<int>;
                ^
1 error generated.
@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@Endilll Endilll added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels Nov 5, 2023
@llvmbot
Copy link
Member Author

llvmbot commented Nov 5, 2023

@llvm/issue-subscribers-clang-frontend

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [13858](https://llvm.org/bz13858) | | Version | trunk | | OS | All | | Reporter | LLVM Bugzilla Contributor |

Extended Description

Sometimes the note for the "previous explicit instantiation" refers to an implicit instantiation instead of the explicit one. For example, take this as test.cpp:

template &lt;typename T&gt;
struct S {
};

void foo() {
    S&lt;int&gt;();
}

template struct S&lt;int&gt;;
template struct S&lt;int&gt;;

Actual Results:

$ clang -c test.cpp
test.cpp:10:17: error: duplicate explicit instantiation of 'S&lt;int&gt;'
template struct S&lt;int&gt;;
                ^
test.cpp:6:5: note: previous explicit instantiation is here
    S&lt;int&gt;();
    ^
1 error generated.

Expected results:

$ clang -c test.cpp
test.cpp:10:17: error: duplicate explicit instantiation of 'S&lt;int&gt;'
template struct S&lt;int&gt;;
                ^
test.cpp:9:17: note: previous explicit instantiation is here
template struct S&lt;int&gt;;
                ^
1 error generated.

@shafik
Copy link
Collaborator

shafik commented Nov 5, 2023

CC @AaronBallman

@Endilll Endilll added the c++ label Nov 6, 2023
@llvmbot
Copy link
Member Author

llvmbot commented Nov 6, 2023

@llvm/issue-subscribers-c-1

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [13858](https://llvm.org/bz13858) | | Version | trunk | | OS | All | | Reporter | LLVM Bugzilla Contributor |

Extended Description

Sometimes the note for the "previous explicit instantiation" refers to an implicit instantiation instead of the explicit one. For example, take this as test.cpp:

template &lt;typename T&gt;
struct S {
};

void foo() {
    S&lt;int&gt;();
}

template struct S&lt;int&gt;;
template struct S&lt;int&gt;;

Actual Results:

$ clang -c test.cpp
test.cpp:10:17: error: duplicate explicit instantiation of 'S&lt;int&gt;'
template struct S&lt;int&gt;;
                ^
test.cpp:6:5: note: previous explicit instantiation is here
    S&lt;int&gt;();
    ^
1 error generated.

Expected results:

$ clang -c test.cpp
test.cpp:10:17: error: duplicate explicit instantiation of 'S&lt;int&gt;'
template struct S&lt;int&gt;;
                ^
test.cpp:9:17: note: previous explicit instantiation is here
template struct S&lt;int&gt;;
                ^
1 error generated.

@AaronBallman AaronBallman added the confirmed Verified by a second party label Nov 6, 2023
@Maetveis
Copy link
Contributor

The diagnostic might even refer to an explicit declaration as in the following example:

template <typename T>
struct S {
    void f(){};
};

extern template void S<int>::f();

template struct S<int>;
template void S<int>::f();

Note the extern in extern template.

<source>:9:23: error: duplicate explicit instantiation of 'f'
    9 | template void S<int>::f();
      |                       ^
<source>:6:30: note: previous explicit instantiation is here
    6 | extern template void S<int>::f();
      |                              ^

Expected:

<source>:9:23: error: duplicate explicit instantiation of 'f'
    9 | template void S<int>::f();
      |                       ^
<source>:8:17: note: previous explicit instantiation is here
    8 | template struct S<int>;
      |                 ^

See this example on Compiler Explorer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

5 participants