[Bug c++/50586] New: Template argument of type "pointer to function" of a template class causes usage error if template is instantiated with pointer-to-private-static-member-function

2011-10-01 Thread mouchtaris at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50586

 Bug #: 50586
   Summary: Template argument of type "pointer to function" of a
template class causes usage error if template is
instantiated with
pointer-to-private-static-member-function
Classification: Unclassified
   Product: gcc
   Version: 4.6.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: mouchta...@gmail.com


Created attachment 25390
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25390
A small test file exhibiting the error.

If there is a declared template class, which accepts a pointer-to-function as a
non-type template parameter:

//
template 
struct caller
  { int operator () (void) const { return (*f)(); } };
//

and is instantiated in a class with a pointer to a private static member
function:

//
class A {
  static int f (void) { return 0; }
public:
  caller<&f> get;
};
//

then G++ reports that "f" is private when used in the context of
caller::operator().

I haven't found anything in the standard that would impose this restriction.

(As a cue, this was reported as an error as well in older version of the vc
compiler, but in version 16.00 it is not an error any more)

I am attaching a small test file. I am not attaching any preprocessed file, as
there is no need. No preprocessor directives are used in this test.

I hope this has not been dealt before.

- Detailed information ---

*** Compiler version: ***
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/spare/root/libexec/gcc/i686-pc-linux-gnu/4.6.1/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.6.1/configure --prefix=/spare/root
Thread model: posix
gcc version 4.6.1 (GCC)


*** Compilation command: ***
g++ -ansi -pedantic -Wall -Wextra t.cpp


*** Compiler output: ***
t.cpp: In member function 'int caller::operator()() const [with int (* f)()
= A::f]':
t.cpp:26:   instantiated from here
t.cpp:13: error: 'static int A::f()' is private
t.cpp:5: error: within this context


[Bug libstdc++/65013] New: [API] std::deque is missing constructors

2015-02-11 Thread mouchtaris at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65013

Bug ID: 65013
   Summary: [API] std::deque is missing constructors
   Product: gcc
   Version: 4.9.2
Status: UNCONFIRMED
  Severity: minor
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: mouchtaris at gmail dot com

std::deque (at least) is missing constructors for copy/move-constructing with a
different allocator.

deque( const deque& other, const Allocator& alloc );
deque( deque&& other, const Allocator& alloc );

(Reminding-mention: the first of these needs to use
std::allocator_traits::select_on_container_copy_construction(alloc)
in case no allocator is provided).


[Bug c++/63924] New: Constexpr constructible expression "is not constexpr" when used in a template non-type argument

2014-11-17 Thread mouchtaris at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63924

Bug ID: 63924
   Summary: Constexpr constructible expression "is not constexpr"
when used in a template non-type argument
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: mouchtaris at gmail dot com

A proper constexpr constructible type is found non-constexpr by the compiler,
under the following conditions:

- it is used in an expression which is passed as a template non-type argument,
- its copy constructor is defaulted (whether explicitly or implicitly).

In the following test case this is demostrated:

// ---
// File t.cpp
// ---
// utils
template  struct require_constexpr {
  static constexpr unsigned value = N;
};
template  constexpr void noop (void) { }

// a constexpr constructible class
struct test { 
  constexpr unsigned size() const { return 0; }
  constexpr test() { }
  constexpr test(const test &) = default;
};

// size wrappers
constexpr auto size0 (test t) { return t.size(); }
// just making sure type "test" is still considered
constexpr auto size1 (test t) { return size0(t); }
// constexpr constructible outside a template argument
constexpr auto size2 (test t) { return size1(t); }
// PROBLEM here
constexpr auto size3 (test t) { return require_constexpr< size0(t) >::value; }

int main (int, char**)
{
  constexpr auto const ar = test { };

  noop<
require_constexpr< size3(ar) >
  >();

  return 0;
}
// ---


Compiling with
g++ -std=c++1y -pedantic -Wall -Wextra -o /tmp/a t.cpp 

and here is the output:
//
t.cpp: In function ‘constexpr auto size3(test)’:
t.cpp:22:68: error: ‘t’ is not a constant expression
 constexpr auto size3 (test t) { return require_constexpr< size0(t) >::value; }
^
t.cpp:22:68: note: in template argument for type ‘unsigned int’ 
t.cpp:22:16: error: invalid return type ‘void’ of constexpr function ‘constexpr
auto size3(test)’
 constexpr auto size3 (test t) { return require_constexpr< size0(t) >::value; }
^
t.cpp: In function ‘int main(int, char**)’:
t.cpp:29:34: error: could not convert template argument ‘size3((ar, test()))’
to ‘unsigned int’
 require_constexpr< size3(ar) >
  ^
t.cpp:30:5: error: no matching function for call to ‘noop()’
   >();
 ^
t.cpp:30:5: note: candidate is:
t.cpp:6:39: note: template constexpr void noop()
 template  constexpr void noop (void) { }
   ^
t.cpp:6:39: note:   template argument deduction/substitution failed:
t.cpp:30:5: error: template argument 1 is invalid
   >();
 ^
//

"test" is still properly constexpr-copy-constructed when used outside
template arguments, as in size1() and size2().

The code segment also compiles cleanly if we define a non-default constructor.
In other words, if we change line
  constexpr test(const test &) = default;
to
  constexpr test(const test &) { }

So the bug (probably) pertrains to defaulting constructors and the use of such
in non-type template arguments.

[Bug c++/63924] Constexpr constructible expression "is not constexpr" when used in a template non-type argument

2014-11-17 Thread mouchtaris at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63924

--- Comment #1 from Nikos  ---
Special thanks and kudos to "T.C." for helping figuring this out:

http://stackoverflow.com/questions/25465379


[Bug c++/63924] Constexpr constructible expression "is not constexpr" when used in a template non-type argument

2014-11-19 Thread mouchtaris at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63924

--- Comment #5 from Nikos  ---
I am sorry, it is missing from the original test case, but

  noop<
require_costexpr< size0(ar) >,
require_constexp< size1(ar) >
  >();

compiles fine. If the issue about test's trivial byte-wise copy construction is
true, shouldn't it cause the degenaration of size0's and size1's constexpr-ness
and cause errors in their usage as template arguments?

Standard-addressing issues are mentioned in the stackoverflow link I have
provided. Specifically, the following comes from §12.8 [class.copy]/p13:

  If the implicitly-defined constructor would satisfy the requirements of a
  constexpr constructor (7.1.5), the implicitly-defined constructor is
constexpr.

I don't see why an implicit constructor copying a literal padding byte is not a
constexpr constructor. The compiler, I assume, is capable of keeping track of
padding bytes as literals at compile time. Or am I mistaken?

Thanks a lot for the fix, and thanks a lot for such a quick response.