<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Template class constructor inside cpp. Unnecessary type requirements"
href="https://bugs.llvm.org/show_bug.cgi?id=50585">50585</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Template class constructor inside cpp. Unnecessary type requirements
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>help0001@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>hey guys,
Today playing with mac os compiling and clang 9.0. And apperntly i noticed a
bug in it.
Normally when you create a template like this:
example.cpp
```cpp
template<typename T>
void execute(T v)
{
/* Your code */
}
```
Because execute isnt been used anywhere in the example.cpp this means this
function wont get compiled. You have to define it in your cpp file on the
bottom the following code to get it compiled:
```cpp
template void execute<int>(int v);
```
Now we have a basic understanding what is required we can go to the clang bug.
When you create a class constructor. It wont return any type. When you declare
the template type as before you see we have a void as a return value. And in
clang 9.0 it has a type as requirement. And this shouldn't be happening.
The following will fail in clang 9.0+ but it should be valid
```cpp
template CPubKey::CPubKey<unsigned char*>(unsigned char*, unsigned char*);
```
Error clang++ gives:
```
src/cpubkey.cpp:261:20: fatal error: qualified reference to 'CPubKey' is a
constructor name rather than a type in this context
```
Example case:
<a href="https://godbolt.org/z/o39MahhKz">https://godbolt.org/z/o39MahhKz</a>
I made the following fix myself.
cpubkey.h
```cpp
/** An encapsulated public key. */
class CPubKey
{
private:
// Just store the serialized data.
// Its length can very cheaply be computed from the first byte.
unsigned char vch[65];
// Compute the length of a pubkey with a given first byte.
static unsigned int GetLen(unsigned char chHeader);
// Set this key data to be invalid
void Invalidate();
public:
// Construct an invalid public key.
CPubKey();
// Construct a public key using begin/end iterators to byte data.
#if defined(__clang__)
template<typename T>
CPubKey(const T pbegin, const T pend)
{
Set(pbegin, pend);
}
#else // defined(__clang__)
template<typename T>
CPubKey(const T pbegin, const T pend);
#endif // defined(__clang__)
```
cpubkey.cpp
```cpp
// Construct a public key using begin/end iterators to byte data.
#if !defined(__clang__)
template<typename T>
CPubKey::CPubKey(const T pbegin, const T pend)
{
Set(pbegin, pend);
}
template CPubKey::CPubKey<unsigned char*>(unsigned char*, unsigned char*);
#endif // !defined(__clang__)
```
Cases:
I manage to test this case on windows, mac and linux. version 9.0 till version
11.0. And all have the same related issue.
Extra:
I manage to discuss this issue on your Discord platform and one person manage
to verify that this is a issue clang++ has.
See here more related to it:
<a href="https://discord.com/channels/636084430946959380/636808521371090956/850316658605293578">https://discord.com/channels/636084430946959380/636808521371090956/850316658605293578</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>