[Bug c++/94799] New: [7.2+ Regression] Calling a member template function fails

2020-04-27 Thread ojman101 at protonmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94799

Bug ID: 94799
   Summary: [7.2+ Regression] Calling a member template function
fails
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ojman101 at protonmail dot com
  Target Milestone: ---

>From gcc version 7.2 and upwards this c++ code, using a member template
function look-up, fails to compile:

template 
struct A {
int a() {
return 42;
}
};

template 
struct B {
int b(A *p) {
return p->template A::a();
}
};

int main() {
A a;
B b;
return b.b(&a);
}

On gcc version 9.3.0 (Gentoo 9.3.0 p2), this output is generated:

main.cc: In member function 'int B::b(A*)':
main.cc:11:32: error: expected ';' before '::' token
   11 | return p->template A::a();
  |^~
  |;
main.cc:11:34: error: '::a' has not been declared
   11 | return p->template A::a();
  |  ^
main.cc: In instantiation of 'int B::b(A*) [with T = int]':
main.cc:18:18:   required from here
main.cc:11:28: error: 'A' is not a member template function
   11 | return p->template A::a();
  |^~~~

This code successfully compiles on new versions of clang, icc and msvc as well
as gcc versions before 7.2.

[Bug c++/95066] New: [C++ 20] Incorrect valid compilation with a conditional explicit

2020-05-11 Thread ojman101 at protonmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066

Bug ID: 95066
   Summary: [C++ 20] Incorrect valid compilation with a
conditional explicit
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ojman101 at protonmail dot com
  Target Milestone: ---

The code below is invalid C++, the line "Foo b = a;" should fail to
compile as implicitly casting is made illegal by the conditional explicit using
the "IsSafelyCastable" predicate.


#include 

template 
class IsSafelyCastable : public std::false_type {};

template <>
class IsSafelyCastable : public std::true_type {};

template 
struct Foo {
template 
explicit(!IsSafelyCastable::value) operator Foo();
};

template 
template 
Foo::operator Foo() {
  return {};
}

int main() {
Foo a;
Foo b = a;
}


Clang 10 correctly evaluates the explicit condition to be true and blocks the
implicit cast. However, GCC 9.3.0 successfully compiles without any errors. I
believe this to be a GCC bug as subtle changes can make GCC produce the correct
error. For example, moving the definition of the function to be inline with the
declaration.

[Bug c++/95066] [C++ 20] Incorrect valid compilation with a conditional explicit

2020-05-11 Thread ojman101 at protonmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95066

--- Comment #1 from Owen Smith  ---

#include 

template 
class IsSafelyCastable : public std::false_type {};

template <>
class IsSafelyCastable : public std::true_type {};

template 
struct Foo {
template 
explicit(!IsSafelyCastable::value) operator Foo() { return {}; }
};

int main() {
Foo a;
Foo b = a;
}


Inlining the definition yields the correct error with GCC 9.3.0:


main.cpp: In function 'int main()':
main.cpp:17:18: error: conversion from 'Foo' to non-scalar type
'Foo' requested
   17 | Foo b = a;
  | 


[Bug c++/95116] New: [C++ 20] Accepts invalid code with decltype dependent type

2020-05-13 Thread ojman101 at protonmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95116

Bug ID: 95116
   Summary: [C++ 20] Accepts invalid code with decltype dependent
type
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ojman101 at protonmail dot com
  Target Milestone: ---

The code below is invalid. The keyword "typename" needs to be inserted before
the decltype expression as "bar" is a dependent type (dependent on template
type T).

template 
struct Bar {
using bar_type = int;
};

template 
struct Foo {
Bar bar;

using foo_type = decltype(bar)::bar_type;
};

int main() {
// Instantiate Foo template
Foo foo;
}

The code successfully compiles with GCC 9.3.0 when running the command "g++
-std=c++2a main.cpp". Note that the "-std=c++2a" must be passed. When passing
"-std=c++17", GCC successfully detects the error and prints:

main.cpp:10:22: error: need 'typename' before 'decltype
(((Foo*)(void)0)->Foo::bar)::bar_type' because 'decltype
(((Foo*)(void)0)->Foo::bar)' is a dependent scope
   10 | using foo_type = decltype(bar)::bar_type;
  |  ^~~~
  |  typename

Running clang 10 with the command "clang++ -std=c++2a main.cpp" also
successfully detects the error and prints:

main.cpp:10:22: error: missing 'typename' prior to dependent type name
'decltype(bar)::bar_type'
using foo_type = decltype(bar)::bar_type;
 ^~~
 typename 
1 error generated.

[Bug c++/95116] [C++ 20] Accepts invalid code with decltype dependent type

2020-05-13 Thread ojman101 at protonmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95116

--- Comment #2 from Owen Smith  ---
Ah ok thanks, I didn't know about P0634R3 :D.