Opened 12 years ago

Closed 12 years ago

#4193 closed Patches (invalid)

Multiple 'using' declarations in multi_index test

Reported by: Chris Jefferson Owned by: Joaquín M López Muñoz
Milestone: Boost 1.43.0 Component: multi_index
Version: Boost Release Branch Severity: Problem
Keywords: Cc:

Description

The following simple patch removes some 'using std::swap' declarations in libs/multi_index/test/test_modifiers.cpp. Note that they are all in the same function under the same macro, and we do not remove the first one, so the code will function identically, but is now correct.

Fixes problem in clang and comeau.

Attachments (1)

test_modifiers.patch (1.0 KB ) - added by Chris Jefferson 12 years ago.
Simple patch to libs/multi_index/test/test_modifiers.cpp

Download all attachments as: .zip

Change History (8)

by Chris Jefferson, 12 years ago

Attachment: test_modifiers.patch added

Simple patch to libs/multi_index/test/test_modifiers.cpp

comment:1 by Steven Watanabe, 12 years ago

Component: Nonemulti_index
Owner: set to Joaquín M López Muñoz

comment:2 by Joaquín M López Muñoz, 12 years ago

Hi Chris,

Can you please explain to me why having redundant using declarations is incorrect? I've just tested it in Comeau online and found no problems. For your reference, the test snippet was:

#include <algorithm>

int main()
{
  int x=0,y=0;
  using std::swap;
  swap(x,y);
  using std::swap;
  swap(x,y);
}

comment:3 by anonymous, 12 years ago

Sorry, the reduced test I was using at comeau was not testing what I thought it was.

It is still the case that this code does not compile in clang, because of the repeated std::swaps, but it may be a fault in clang, which could be fixed rather than introducing an #ifdef or patch.

Will report back after further investigation

comment:4 by anonymous, 12 years ago

From Doug Gregor, it appears that clang is right to reject the current code:

Clang is correct; Comeau and g++ are wrong not to diagnose these errors. See C++ [namespace.udecl]p10:

A using-declaration is a declaration and can therefore be used repeatedly

where (and only where) multiple declarations are allowed.

comment:5 by Steven Watanabe, 12 years ago

Huh?

The standard reference seems to imply that

#include <algorithm>
int main() {
    using std::swap;
    using std::swap;
}

is legal iff

int main() {
    void swap(int&, int&);
    void swap(int&, int&);
}

is legal. I would find it very weird if the latter is illegal.

in reply to:  5 comment:6 by Douglas Gregor, 12 years ago

Oops, thanks Steven! I was convinced that the latter was ill-formed, but I've reviewed the standard again and you are correct. Clang now implements the right semantics, so we should close out this patch as being wrong. Sorry about that!

comment:7 by Douglas Gregor, 12 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.