[Bug c++/87820] Explicit user-defined casting inside a template class working in implicit conversion inside function template

2019-10-08 Thread fgsimperium at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87820

--- Comment #2 from Francisco Gallego Salido  
---
(In reply to ExtComm.CODA from comment #1)
> clang and intel-compiler don't fail

Btw I've just realized that the example is wrong, because the class has only
default constructor and I'm initializing the variable 'a' with an integer. It
was supposed to be dafault initialized (even though it isn't that big of a
deal).

And no, in clang and MSVC neither of the code snippets compile, which is what's
supposed to happen.

[Bug c++/87820] New: Explicit user-defined casting inside a template class working in implicit conversion inside function template

2018-10-30 Thread fgsimperium at hotmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87820

Bug ID: 87820
   Summary: Explicit user-defined casting inside a template class
working in implicit conversion inside function
template
   Product: gcc
   Version: 8.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fgsimperium at hotmail dot com
  Target Milestone: ---

Let's consider this class definition:

template 
class Test{
public:
Test() {}
explicit operator T() const { return T(); }
};

Then this code below fails to compile (as expected):

int main(){
Test a(10);
unsigned j = a; // error: cannot convert 'Test' to 'unsigned
int' in initialization
}

But this other code compiles fine:

template
void test(){
Test a(10);
T j = a; // This should be an error
}

int main(){
test();
}

The second snippet allows an implicit conversion from Test to T, even though
the casting is declared 'explicit'.

It's been tested in every compiler version from 4.5.3 to 8.2. The command line
options are (in Ubuntu 16.04 LTS):

-std=c++0x -Wall -Wextra -pedantic # c++14 an c++17 have the same behaviour