[Bug c++/95772] New: warning desired when default operator= cannot be constructued

2020-06-19 Thread marcpawl at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95772

Bug ID: 95772
   Summary: warning desired when default operator= cannot be
constructued
   Product: gcc
   Version: 10.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: marcpawl at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/eXckPe

#include 

class Const {
 public:
  int const i_;

  Const(int i) : i_(i) {}

  Const& operator=(Const& rhs) = default;
};

int main(int argc, char**) {
  Const c{argc};
  static_assert(!std::is_assignable::value,
"should not be able to assign i_");
#ifdef ASSIGN
  Const d{argc + 1};
  d = c;
#endif
  return c.i_;
}

I expected a diagnostic saying that operator= cannot be defaulted which is seen
if the ASSIGN code is enabled.  The code compiles cleanly.

When I wrote this bug in a large code base  with -03 and -flto the code will
fail with illegal instructions and other memory corruption errors.  No problem
without optimization.

[Bug c++/95772] warning desired when default operator= cannot be constructued

2020-06-19 Thread marcpawl at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95772

--- Comment #2 from Marc Pawlowsky  ---
I understand that it is deleted, but if somebody says it should be defaulted
when it is defaulted that is most likely an error, and it would be nice if a
warning were generated.

[Bug c++/95772] warning desired when default operator= cannot be constructued

2020-06-20 Thread marcpawl at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95772

Marc Pawlowsky  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #4 from Marc Pawlowsky  ---
"Do the default thing" vs "generate the default".  

What would your feeling be for a clang-tidy rule under readability?  It was a
surprise to me, especially since I never have actually read the spec since
C++98, just training articles/videos and quick scans through the odd committee
paper.

[Bug c++/92735] New: unused member variable causes code to compile for member to function for undefined function

2019-11-29 Thread marcpawl at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92735

Bug ID: 92735
   Summary: unused member variable causes code to compile for
member to function for undefined function
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: marcpawl at gmail dot com
  Target Milestone: ---

Marc Pawlowsky 
Thu, Nov 28, 8:25 PM (23 hours ago)
to gcc-bugzilla-account-request

https://godbolt.org/z/SFZmZJ

In clang you get 
no member names 'hello' in 'Bad'
which is the expected result.

In all GCC versions using --std=c++17 from 5.2 onwards the code compiles.

#include 
#include 
struct Foo {
virtual void hello(int) = 0;
};

struct Bar : public Foo {
void hello(int) override {};
};

struct Bad { };

template 
struct is_Foo {
using hello_fn_t = void (T::*)(int);
constexpr static void (T::*hello)(int) = &T::hello;
static constexpr bool value=true;
};

template 
auto say(T& t) -> std::enable_if_t::value, void>{
//U u; // Line 22
//t.hello(4); // Line 23
puts("hello\n");
}

int main()
{
//Bar b;;
//Foo& f = b;
//say(b);
//say(f);
Bad bad;
say(bad);
}

If you change say to
template >
void say(T& t)
{
U u; // Line 22
//t.hello(4); // Line 23
}
you get the same errors in clang, but no errors in gcc.

== 
on a related not I sent to clang bug report where if value is not static the
code will compile.

[Bug c++/92735] unused member variable causes code to compile for member to function for undefined function

2019-12-03 Thread marcpawl at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92735

--- Comment #4 from Marc Pawlowsky  ---
(In reply to Jonathan Wakely from comment #2)
> For the case reported here, Clang and EDG do reject it, but I'm not yet
> convinced GCC is wrong to accept it.
> 
> The implicit instantiation of is_Foo causes:
> 
> "the implicit instantiation of the declarations, but not of the definitions,
> of the non-deleted class member functions, member classes, scoped member
> enumerations, static data members, member templates, and friends;"
> 
> and:
> 
> "in particular, the initialization (and any associated side effects) of a
> static data member does not occur unless the static data member is itself
> used in a way that requires the definition of the static data member to
> exist."
> 
> Nothing requires the instantiation of is_Foo::hello.

FYI, Forcing the use of hello does cause a compile time error.
template 
struct is_Foo {
using hello_fn_t = void (T::*)(int);
constexpr static void (T::*hello)(int) = &T::hello;
static constexpr bool value=(!!hello);
};
source>:16:46: error: 'hello' is not a member of 'Bad'

   16 | constexpr static void (T::*hello)(int) = &T::hello;

[Bug c++/92852] New: location references block not in block tree

2019-12-06 Thread marcpawl at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92852

Bug ID: 92852
   Summary: location references block not in block tree
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: marcpawl at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/Kh3xWR

Add...


#include 
#include 
#include 

 void foo()
 {
 std::ostream& message_stream = std::cout;
 auto data = std::make_tuple(3,4.5,"cd");
 auto format = [&message_stream](auto && x) { message_stream << x ;};
std::apply([&](auto const& ...x){(..., format(x));}, data);
 }

x86-64 gcc (trunk) (Editor #1, Compiler #2) C++
x86-64 gcc (trunk)
-O0 -std=c++17
1

x86-64 gcc (trunk) - 2085ms
#2 with x86-64 gcc (trunk)
: In lambda function:

:12:2: error: location references block not in block tree

   12 |  }

  |  ^

&cout

std::basic_ostream::operator<< (&cout, _1);

during IPA pass: *free_lang_data

:12:2: internal compiler error: verify_gimple failed

Please submit a full bug report,

with preprocessed source if appropriate.

See <https://gcc.gnu.org/bugs/> for instructions.

Compiler returned: 1

[Bug c++/115580] New: decltype of nullptr error with -Werror=nonnull

2024-06-21 Thread marcpawl at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115580

Bug ID: 115580
   Summary: decltype of nullptr error with -Werror=nonnull
   Product: gcc
   Version: 14.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: marcpawl at gmail dot com
  Target Milestone: ---

-Werror=nonnull returns error when using nullptr to get type of member
function.

Even though we are using -Werror=nonnull, there should be no diagnostic
since the function is never evaluated, and it is non-virtual.


https://godbolt.org/z/3oh1199Wh
https://stackoverflow.com/questions/5580253/how-do-i-get-the-return-type-of-a-member-function-without-an-object


class WithMember {
public:
  int foo();
};

decltype(((WithMember*)nullptr)->foo()) footype;

:7:37: error: 'this' pointer is null [-Werror=nonnull]
7 | decltype(((WithMember*)nullptr)->foo()) footype;
  |  ~~~^~
:4:7: note: in a call to non-static member function 'int
WithMember::foo()'
4 |   int foo();
  |   ^~~
:7:37: error: 'this' pointer is null [-Werror=nonnull]
7 | decltype(((WithMember*)nullptr)->foo()) footype;
  |  ~~~^~
:4:7: note: in a call to non-static member function 'int
WithMember::foo()'
4 |   int foo();
  |   ^~~
cc1plus: some warnings being treated as errors
Compiler returned: 1