Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#851 closed defect (fixed)

Use delete on noncopyable classes

Reported by: cvvergara Owned by: strk
Priority: trivial Milestone: 3.7.0
Component: Core Version: 3.6.2
Severity: Unassigned Keywords:
Cc:

Description

C++11

When the copy construction and assignment wants to be explicitly forbidden by the author, it needs to have the = delete

Current code looks like:

// Declare type as noncopyable
RayCrossingCounter(const RayCrossingCounter& other);
RayCrossingCounter& operator=(const RayCrossingCounter& rhs);

(1) If it is used externally, it will be a compiler error (because it is private). (expected)

(2) But if it is referenced internally or by a friend, then it will produce a link error because the definition does not exist.

In C++11:

// Declare type as noncopyable
RayCrossingCounter(const RayCrossingCounter& other) = delete;
RayCrossingCounter& operator=(const RayCrossingCounter& rhs) = delete;

Here, (2) the compiler will note this at compilation - no linker errors and clear intent.

Change History (5)

comment:1 Changed 5 months ago by robe

is this same behavior for lower than C++11?

Note 3.7+ hasn't been released yet so we can standardize on C++11 if we want to.

3.6+ has to work for lower. Anyway this should probably go in 3.7 and not lower, so switching milestone.

comment:2 Changed 5 months ago by robe

Milestone: 3.6.33.7.0

comment:3 Changed 5 months ago by cvvergara

As far as I know = delete starts from C++11

http://en.cppreference.com/w/cpp/language/default_constructor

comment:4 Changed 5 months ago by cvvergara

Resolution: fixed
Status: newclosed

comment:5 Changed 5 months ago by robe

@cvvergara Next time, can you try in the commit putting in

Closes #whatever_the_ticket_number in the git commit message.

It should automatically reference back to the ticket with the git ref. and close the ticket automatically.

Note: See TracTickets for help on using tickets.