Skip to content

Constificator: suggests this-const for BoundedBuffer::push_many #31

Description

@The-Compiler

I'm using Archlinux, with Cevelop 1.12.1-201907081203 and Constificator 1.12.2.20190710144.

With this source code (from BoundedBuffer):

	template<typename Head, typename... Tail>
	void push_many(Head && head, Tail &&... tail) {
		push(std::forward<Head>(head));
		if constexpr (sizeof...(Tail)) {
			push_many(std::forward<Tail>(tail)...);
		}
	}

	template<typename E>
	void push(E && element) {
		ensureNotFull();
		auto const position = &(*this)[sizeCounter];
		new (position) value_type{ std::forward<E>(element) };
		sizeCounter++;
	}

I'm getting:

image

But obviously push_many can't be this-const, as it calls push which isn't const:

In file included from ../src/bounded_buffer_student_suite.cpp:4:
../src/BoundedBuffer.h: In instantiation of ‘void BoundedBuffer<T>::push_many(Head&&, Tail&& ...) const [with Head = int; Tail = {int, int}; T = int]’:
../src/bounded_buffer_student_suite.cpp:17:26:   required from here
../src/BoundedBuffer.h:112:3: error: passing ‘const BoundedBuffer<int>’ as ‘this’ argument discards qualifiers [-fpermissive]
  112 |   push(std::forward<Head>(head));
      |   ^~~~
../src/BoundedBuffer.h:150:7: note:   in call to ‘void BoundedBuffer<T>::push(E&&) [with E = int; T = int]’
  150 |  void push(E && element) {
      |       ^~~~

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions