在c++ 11中引入了哪些突破性的变化?

时间:2022-02-23 21:03:15

I know that at least one of the changes in C++11 that will cause some old code to stop compiling: the introduction of explicit operator bool() in the standard library, replacing old instances of operator void*(). Granted, the code that this will break is probably code that should not have been valid in the first place, but it's still a breaking change nonetheless: programs that used to be valid no longer are.

我知道c++ 11中至少有一个更改会导致一些旧代码停止编译:在标准库中引入显式操作符bool(),替换操作符void*()的旧实例。当然,这将破坏的代码可能一开始就不应该是有效的,但它仍然是一个破坏性的改变:曾经有效的程序现在已经失效了。

Are there any other breaking changes?

还有其他的突破吗?

10 个解决方案

#1


169  

The FDIS has a section for incompatibilities, at appendix C.2 "C++ and ISO C++ 2003".

FDIS有一个不兼容的部分,在附录C.2“c++和ISO c++ 2003”。

Summary, paraphrasing the FDIS here, to make it (better) suitable as a SO answer. I added some examples of my own to illustrate the differences.

总结,改写这里的FDIS,使它(更好)适合作为SO答案。我添加了一些我自己的例子来说明差异。

There are a few library-related incompatibilities where I don't exactly know the implications of, so I leave those for others to elaborate on.

有一些与图书馆有关的不兼容性,我不知道其中的含义,所以我把这些留给其他人来详细说明。

Core language


#define u8 "abc"
const char *s = u8"def"; // Previously "abcdef", now "def"

#define _x "there"
"hello"_x // now a user-defined-string-literal. Previously, expanded _x .

New keywords: alignas, alignof, char16_t, char32_t, constexpr, decltype, noexcept, nullptr, static_assert, and thread_local

新关键词:alignas, alignof, char16_t, char32_t, constexpr, decltype, noexcept, nullptr, static_assert, thread_local


Certain integer literals larger than can be represented by long could change from an unsigned integer type to signed long long.

某些大于long表示的整数文本可以从无符号整数类型更改为有符号长。


Valid C++ 2003 code that uses integer division rounds the result toward 0 or toward negative infinity, whereas C++0x always rounds the result toward 0.

使用整数划分的有效c++ 2003代码将结果趋向于0或趋向于负无穷大,而c++ 0x总是将结果转到0。

(admittedly not really a compatibility problem for most people).

(诚然,对大多数人来说,这并不是一个真正的兼容性问题)。


Valid C++ 2003 code that uses the keyword auto as a storage class specifier may be invalid in C++0x.

使用关键字auto作为存储类说明符的有效c++ 2003代码在c++ 0x中可能是无效的。


Narrowing conversions cause incompatibilities with C++03. For example, the following code is valid in C++ 2003 but invalid in this International Standard because double to int is a narrowing conversion:

收缩转换导致与c++ 03的不兼容。例如,以下代码在c++ 2003中是有效的,但是在这个国际标准中无效,因为双到int是一种收缩转换:

int x[] = { 2.0 };

Implicitly-declared special member functions are defined as deleted when the implicit definition would have been ill-formed.

隐式声明的特殊成员函数被定义为删除,当隐式定义是不恰当的。

A valid C++ 2003 program that uses one of these special member functions in a context where the definition is not required (e.g., in an expresion that is not potentially evaluated) becomes ill-formed.

一个有效的c++ 2003程序,在不需要定义的情况下(例如,在没有可能被评估的情况下)使用这些特殊的成员函数之一,会变得不规范。

Example by me:

我的例子:

struct A { private: A(); };
struct B : A { };
int main() { sizeof B(); /* valid in C++03, invalid in C++0x */ }

Such sizeof tricks have been used by some SFINAE, and needs to be changed now :)

一些SFINAE使用了这种尺寸的技巧,现在需要改变:)


User-declared destructors have an implicit exception specification.

用户声明的析构函数具有隐式异常规范。

Example by me:

我的例子:

struct A {
  ~A() { throw "foo"; }
};

int main() { try { A a; } catch(...) { } }

This code calls terminate in C++0x, but does not in C++03. Because the implicit exception specification of A::~A in C++0x is noexcept(true).

此代码调用在c++ 0x中终止,但不使用c++ 03。因为c++ 0x中A::~A的隐式异常规范是noexcept(true)。


A valid C++ 2003 declaration containing export is ill-formed in C++0x.

包含出口的有效的c++ 2003声明在c++ 0x中是不正确的。


A valid C++ 2003 expression containing > followed immediately by another > may now be treated as closing two templates.

一个包含>的有效c++ 2003表达式,紧接着是另一个>,现在可以将其视为关闭两个模板。

In C++03, >> would always be the shift-operator token.

在c++ 03中,>>始终是移位操作符令牌。


Allow dependent calls of functions with internal linkage.

允许内部连接的函数的依赖调用。

Example by me:

我的例子:

static void f(int) { }
void f(long) { }

template<typename T>
void g(T t) { f(t); }

int main() { g(0); }

In C++03, this calls f(long), but in C++0x, this calls f(int). It should be noted that in both C++03 and C++0x, the following calls f(B) (the instantiation context still only considers extern linkage declarations).

在c++ 03中,它调用f(long),而在c++ 0x中,它调用f(int)。需要注意的是,在c++ 03和c++ 0x中,以下调用f(B)(实例化上下文仍然只考虑外部链接声明)。

struct B { };
struct A : B { };

template<typename T>
void g(T t) { f(t); }

static void f(A) { }
void f(B) { }

int main() { A a; g(a); }

The better matching f(A) is not taken, because it does not have external linkage.

由于f(A)没有外部连接,所以没有更好的匹配。


Library changes

Valid C++ 2003 code that uses any identifiers added to the C++ standard library of C++0x may fail to compile or produce different results in This International Standard.

使用添加到c++ c++ c++标准库的任何标识符的有效c++ 2003代码在这个国际标准中可能无法编译或产生不同的结果。


Valid C++ 2003 code that #includes headers with names of new C++0x standard library headers may be invalid in this International Standard.

在这个国际标准中,包含带有新c++ 0x标准库标头的#的有效c++ 2003代码可能无效。


Valid C++ 2003 code that has been compiled expecting swap to be in <algorithm> may have to instead include <utility>

有效的c++ 2003代码已经编译,期望交换在 <算法> 中,但可能必须包含


The global namespace posix is now reserved for standardization.

全局命名空间posix现在预留给标准化。


Valid C++ 2003 code that defines override, final, carries_dependency, or noreturn as macros is invalid in C++0x.

在c++ 0x中,定义重写、final、carries_dependency或noreturn为宏的有效c++ 2003代码无效。

#2


27  

The meaning of the auto keyword changed.

自动关键字的意思改变了。

#3


23  

Breaking change?

断改变?

Well, for one thing, if you used decltype, constexpr, nullptr, etc. as identifiers then you may be in trouble...

首先,如果您使用了decltype, constexpr, nullptr等作为标识符,那么您可能就有麻烦了……

#4


21  

Some core incompatibilities that are not covered by the incompatibilities section:

一些不兼容的核心不兼容部分:


C++0x treats the injected class name as a template, if the name is passed as an argument to a template template parameter, and as a type if it is passed to a template type parameter.

c++ 0x将注入的类名视为模板,如果将名称作为参数传递给模板模板参数,并将其作为类型传递给模板类型参数。

Valid C++03 code may behave differently if it relies on the injected class name to be always a type in these scenarios. Example code taken from my clang PR

如果有效的c++ 03代码依赖于在这些场景中注入的类名始终是类型,那么它的行为可能会有所不同。示例代码取自我的clang PR

template<template<typename> class X>
struct M { };

template<template<typename> class X>
void g(int = 0); // #1

template<typename T>
void g(long = 0); // #2

template<typename T>
struct A {
  void f() {
    g<A>(); /* is ambiguous in C++0x */
    g<A>(1); /* should choose #1 in C++0x */
  }
};

void h() {
  A<int> a;
  a.f();
}

In C++03, the code calls the second g both times.

在c++ 03中,代码两次都调用第二个g。


C++0x makes some names that were dependent in C++03 to be now non-dependent. And requires name lookup for non-dependent qualified names that refer to members of the current class template to be repeated at instantiation, and requires verification that these names lookup the same way as done at the template definition context.

c++ 0x使得一些名字在c++ 03中是不相关的。并且需要对引用当前类模板的成员的非相关限定名进行名称查找,并需要验证这些名称的查找方式是否与模板定义上下文相同。

Valid C++03 code that depends on the dominance rule may now not compile anymore because of this change.

基于支配规则的有效c++ 03代码现在可能不会再编译了,因为这个更改。

Example:

例子:

struct B { void f(); };

template<typename T>
struct A : virtual B { void f(); };

template<typename T>
struct C : virtual B, A<T> {
  void g() { this->f(); }
};

int main() { C<int> c; c.g(); }

This valid C++03 code that calls A<int>::f is not valid in C++0x, because name lookup when instantiating will find A<int>::f as opposed to B::f, causing a conflict with the at-definition lookup.

调用 :::f的有效c++ 03代码在c++ 0x中无效,因为实例化时的名称查找将发现 : f,而不是B::f,与at-definition查找产生冲突。

At this point, it is not clear whether that is a defect in the FDIS. The committee is aware of this and will evaluate the situation.

目前尚不清楚这是否是FDIS的缺陷。委员会认识到这一点,并将评估局势。


A using declaration where the last part is the same as the identifier in the last part of the qualifier in the qualified name denoting a base class, that using declaration now names the constructor, instead of members with that name.

一个使用声明,其中最后的部分与限定符的最后部分中的标识符在表示基类的限定名中的标识符相同,现在使用声明命名构造函数,而不是使用该名称的成员。

Example:

例子:

struct A { protected: int B; };
typedef A B;

struct C : B {
  // inheriting constructor, instead of bringing A::B into scope
  using B::B;
};

int main() { C c; c.B = 0; }

The above example code is well-formed in C++03, but ill-formed in C++0x, as A::B is still inaccessible in main.

上面的示例代码在c++ 03中很好地形成,但是在c++ 0x中是不正确的,因为在main中仍然无法访问B。

#5


13  

How is the introduction of explicit conversion operators a breaking change? The old version will still just be as "valid" as before.

如何引入显式转换操作符?旧版本仍将和以前一样“有效”。

Yes, the change from operator void*() const to explicit operator bool() const will be a breaking change, but only if it is used in a way that is wrong in and out of itself. Conforming code won't be broken.

是的,从操作符void*() const到显式操作符bool() const的更改将是一个彻底的更改,但只有在以错误的方式使用时才会如此。一致性代码不会被破坏。

Now, another breaking change is the banning of narrowing conversions during aggregate initialization:

现在,另一个重大的变化是在聚合初始化期间禁止收缩转换:

int a[] = { 1.0 }; // error

Edit: Just rememberer, std::identity<T> will be removed in C++0x (see the note). It's a convenience struct to make types dependent. Since the struct really doesn't do much, this should fix it:

编辑:记住,std::identity 将在c++ 0x中删除(请参阅注释)。它是一个方便的结构,使类型依赖。由于结构体真的没什么作用,这应该可以修复它:

template<class T>
struct identity{
  typedef T type;
};

#6


13  

Stream extraction failure is treated differently.

对流抽采失败的处理不同。

Example

#include <sstream>
#include <cassert>

int main()
{
   std::stringstream ss;
   ss << '!';

   int x = -1;

   assert(!(ss >> x)); // C++03 and C++11
   assert(x == -1);    // C++03
   assert(x == 0);     // C++11
}

Change proposal

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3246.html#23

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3246.html # 23

Standard reference

[C++03: 22.2.2.1.2/11]: The result of stage 2 processing can be one of

[C+ 03: 22.2.1.2 /11]:第二阶段处理的结果可以是

  • A sequence of chars has been accumulated in stage 2 that is converted (according to the rules of scanf) to a value of the type of val. This value is stored in val and ios_base::goodbit is stored in err.
  • 第2阶段积累了一系列chars,并将其转换为val类型的值(根据scanf的规则),该值存储在val中,ios_base: goodbit存储在err中。
  • The sequence of chars accumulated in stage 2 would have caused scanf to report an input failure. ios_base::failbit is assigned to err. [ed: Nothing is stored in val.]
  • 第2阶段积累的chars序列会导致scanf报告输入失败。ios_base: failbit被分配给err。[ed:没有任何东西被储存在val中。]

[C++11: 22.4.2.1.2/3]: [..] The numeric value to be stored can be one of:

[c++ 11:22.4.2.1.2/3]:[. .]所存储的数值可为:

  • zero, if the conversion function fails to convert the entire field. ios_base::failbit is assigned to err.
  • 零,如果转换函数不能转换整个字段。ios_base: failbit被分配给err。
  • the most positive representable value, if the field represents a value too large positive to be represented in val. ios_base::failbit is assigned to err.
  • 如果字段表示的值太大,无法在val. ios_base::failbit中表示,则为最积极的可表示值。
  • the most negative representable value or zero for an unsigned integer type, if the field represents a value too large negative to be represented in val. ios_base::failbit is assigned to err.
  • 对于无符号整数类型,如果字段表示一个值太大的负数,则表示在val. ios_base中,最负的可表示值或零值::failbit被指定为err。
  • the converted value, otherwise.
  • 转换后的值,否则。

The resultant numeric value is stored in val.

生成的数值存储在val中。

Implementations

  • GCC 4.8 correctly outputs for C++11:

    GCC 4.8 C+ 11的正确输出:

    Assertion `x == -1' failed

    断言' x == -1'失败

  • GCC 4.5-4.8 all output for C++03 the following, which would appear to be a bug:

    GCC 4.5-4.8 C+ 03的所有输出如下,这似乎是一个bug:

    Assertion `x == -1' failed

    断言' x == -1'失败

  • Visual C++ 2008 Express correctly outputs for C++03:

    Visual c++ 2008正确输出c++ 03:

    Assertion failed: x == 0

    断言失败:x = 0

  • Visual C++ 2012 Express incorrectly outputs for C++11, which would appear to be a status-of-implementation issue:

    Visual c++ 2012 Express错误地输出了c++ 11,这似乎是一个执行状态问题:

    Assertion failed: x == 0

    断言失败:x = 0

#7


8  

There are numerous changes to the containers library that allow more efficient code but silently break backwards compatibility for a few corner cases.

容器库中有许多更改,这些更改允许更有效的代码,但在一些情况下会悄悄地破坏向后兼容性。

Consider, for example, std::vector, default construction, C++0x, and breaking changes.

例如,考虑std::vector、默认结构、c++ 0x和中断更改。

#8


7  

There's been a lot of discussion of implicit move breaking backward compatibility

有很多关于隐式移动打破向后兼容性的讨论

(an older page with relevant discussion)

(有相关讨论的旧页)

If you read down into the comments, implicit move return is also a breaking change.

如果你往下读评论,隐式移动返回也是一个突破性的改变。

#9


6  

struct x {
   x(int) {}
};

void f(auto x = 3) { }

int main() {
   f();
}

C++03: valid.

c++ 03:有效。

C++0x: error: parameter declared 'auto'

c++ 0x:错误:参数声明为“auto”

#10


-1  

Language Features

  1. Uniform and general initialization using {}
  2. 使用{}进行统一和通用初始化
  3. auto
  4. 汽车
  5. Prevention of narrowing
  6. 预防缩小
  7. constexpr
  8. constexpr
  9. Range based for loop
  10. 基于范围的for循环
  11. nullptr
  12. nullptr
  13. enum class
  14. 枚举类
  15. static_assert
  16. static_assert
  17. std::initializer_list
  18. std::initializer_list
  19. Rvalue references (move semantics)
  20. 右值引用(语义)
  21. >>
  22. > >
  23. Lambdas
  24. λ
  25. Variadic templates
  26. 可变模板
  27. Type and template aliases
  28. 类型和模板的别名
  29. Unicode characters
  30. Unicode字符
  31. long long integer type
  32. 长长的整数类型
  33. alignas and alignof
  34. alignas和alignof
  35. decltype
  36. decltype
  37. Raw string literals
  38. 原始字符串
  39. Generalized POD
  40. 广义豆荚
  41. Generalized unions
  42. 广义的工会
  43. Local classes as template arguments
  44. 本地类作为模板参数
  45. Suffix return type syntax
  46. 后缀返回类型的语法
  47. [[carries_dependency]] and [[noreturn]]
  48. [[carries_dependency]]和[[noreturn]]
  49. noexcept specifier
  50. noexcept说明符
  51. noexcept operator.
  52. noexcept算子。
  53. C99 features:
    • extended integral types
    • 扩展积分类型
    • concatenation of narrow/wide string
    • 串联的窄或宽字符串
    • _ _ STDC_HOSTED _ _
    • _stdc_host __
    • _Pragma(X)
    • _Pragma(X)
    • vararg macros and empty macro arguments
    • vararg宏和空宏参数
  54. C99特性:扩展的整数类型连接窄/宽字符串_stdc_host ____pragma (X) vararg宏和空宏参数
  55. _ _ func _ _
  56. 是什么意思
  57. Inline namespaces
  58. 内联名称空间
  59. Delegating constructors
  60. 委托构造函数
  61. In-class member initializers
  62. 课堂成员初始化
  63. default and delete
  64. 违约和删除
  65. Explicit conversion operators
  66. 显式转换操作符
  67. User-defined literals
  68. 用户定义的文字
  69. Extern templates
  70. 外面的模板
  71. Default template arguments for function templates
  72. 函数模板的默认模板参数
  73. Inheriting constructors
  74. 继承的构造函数
  75. override and final
  76. 覆盖和最终
  77. Simpler and more general SFINAE rule
  78. 更简单和更一般的SFINAE规则
  79. Memory model
  80. 内存模型
  81. thread_local
  82. thread_local

Standard-Library Components

  1. initializer_list for containers
  2. initializer_list的容器
  3. Move semantics for containers
  4. 移动语义容器
  5. forward_list
  6. forward_list
  7. Hash containers
    • unordered_map
    • unordered_map
    • unordered_multimap
    • unordered_multimap
    • unordered_set
    • unordered_set
    • unordered_multiset
    • unordered_multiset
  8. 散列容器unordered_map unordered_multimap unordered_set unordered_set unordered_multiset
  9. Resource management pointers
    • unique_ptr
    • unique_ptr
    • shared_ptr
    • 要查看
    • weak_ptr
    • weak_ptr
  10. 资源管理指针unique_ptr shared_ptr weak_ptr
  11. Concurrency support
    • thread
    • 线程
    • mutexes
    • 互斥锁
    • locks
    • condition variables
    • 条件变量
  12. 并发性支持线程互斥锁条件变量
  13. Higher-level concurrency support
    • packaged_thread
    • packaged_thread
    • future
    • 未来
    • promise
    • 承诺
    • async
    • 异步
  14. 更高级别的并发支持packaged_thread未来承诺异步
  15. tuples
  16. 元组
  17. regex
  18. 正则表达式
  19. Random numbers
    • uniform_int_distribution
    • uniform_int_distribution
    • normal_distribution
    • normal_distribution
    • random_engine
    • random_engine
    • etc.
    • 等。
  20. 随机数均匀分布正态分布随机引擎等。
  21. Integer type names, such as int16_t , uint32_t , and int_fast64_t
  22. 整数类型名称,如int16_t、uint32_t和int_fast64_t
  23. array
  24. 数组
  25. Copying and rethrowing exceptions
  26. 复制并将异常
  27. system_error
  28. system_error
  29. emplace() operations for containers
  30. 安置()操作容器
  31. constexpr functions
  32. constexpr功能
  33. Systematic use of noexcept functions
  34. noexcept函数的系统使用
  35. function and bind
  36. 函数和绑定
  37. String to numeric value conversions
  38. 字符串到数值转换
  39. Scoped allocators
  40. 作用域的分配器
  41. Type traits
  42. 类型特征
  43. Time utilities: duration and time_point
  44. 时间工具:持续时间和时间点
  45. ratio
  46. quick_exit
  47. quick_exit
  48. More algorithms, such as move() , copy_if() , and is_sorted()
  49. 更多的算法,如move()、copy_if()和is_sort ()
  50. Garbage collection ABI
  51. 垃圾收集ABI
  52. atomics
  53. 原子

Deprecated Features

  1. Generation of the copy constructor and the copy assignment for a class with a destructor.
  2. 为具有析构函数的类生成复制构造函数和复制赋值。
  3. Assign a string literal to a char *.
  4. 将字符串字面量赋给char *。
  5. C++98 exception specification
    • unexcepted_handler
    • unexcepted_handler
    • set_unexpected
    • set_unexpected
    • get_unexpected
    • get_unexpected
    • unexpected
    • 意想不到的
  6. c++ 98异常规范unexcepted_handler set_unexpected get_unexpected unexpected unexpected
  7. Function objects and associated functions
  8. 函数对象和相关函数
  9. auto_ptr
  10. auto_ptr
  11. register
  12. 注册
  13. ++ on a bool
  14. bool + +
  15. export
  16. 出口
  17. C-style casts
  18. c风格的投

#1


169  

The FDIS has a section for incompatibilities, at appendix C.2 "C++ and ISO C++ 2003".

FDIS有一个不兼容的部分,在附录C.2“c++和ISO c++ 2003”。

Summary, paraphrasing the FDIS here, to make it (better) suitable as a SO answer. I added some examples of my own to illustrate the differences.

总结,改写这里的FDIS,使它(更好)适合作为SO答案。我添加了一些我自己的例子来说明差异。

There are a few library-related incompatibilities where I don't exactly know the implications of, so I leave those for others to elaborate on.

有一些与图书馆有关的不兼容性,我不知道其中的含义,所以我把这些留给其他人来详细说明。

Core language


#define u8 "abc"
const char *s = u8"def"; // Previously "abcdef", now "def"

#define _x "there"
"hello"_x // now a user-defined-string-literal. Previously, expanded _x .

New keywords: alignas, alignof, char16_t, char32_t, constexpr, decltype, noexcept, nullptr, static_assert, and thread_local

新关键词:alignas, alignof, char16_t, char32_t, constexpr, decltype, noexcept, nullptr, static_assert, thread_local


Certain integer literals larger than can be represented by long could change from an unsigned integer type to signed long long.

某些大于long表示的整数文本可以从无符号整数类型更改为有符号长。


Valid C++ 2003 code that uses integer division rounds the result toward 0 or toward negative infinity, whereas C++0x always rounds the result toward 0.

使用整数划分的有效c++ 2003代码将结果趋向于0或趋向于负无穷大,而c++ 0x总是将结果转到0。

(admittedly not really a compatibility problem for most people).

(诚然,对大多数人来说,这并不是一个真正的兼容性问题)。


Valid C++ 2003 code that uses the keyword auto as a storage class specifier may be invalid in C++0x.

使用关键字auto作为存储类说明符的有效c++ 2003代码在c++ 0x中可能是无效的。


Narrowing conversions cause incompatibilities with C++03. For example, the following code is valid in C++ 2003 but invalid in this International Standard because double to int is a narrowing conversion:

收缩转换导致与c++ 03的不兼容。例如,以下代码在c++ 2003中是有效的,但是在这个国际标准中无效,因为双到int是一种收缩转换:

int x[] = { 2.0 };

Implicitly-declared special member functions are defined as deleted when the implicit definition would have been ill-formed.

隐式声明的特殊成员函数被定义为删除,当隐式定义是不恰当的。

A valid C++ 2003 program that uses one of these special member functions in a context where the definition is not required (e.g., in an expresion that is not potentially evaluated) becomes ill-formed.

一个有效的c++ 2003程序,在不需要定义的情况下(例如,在没有可能被评估的情况下)使用这些特殊的成员函数之一,会变得不规范。

Example by me:

我的例子:

struct A { private: A(); };
struct B : A { };
int main() { sizeof B(); /* valid in C++03, invalid in C++0x */ }

Such sizeof tricks have been used by some SFINAE, and needs to be changed now :)

一些SFINAE使用了这种尺寸的技巧,现在需要改变:)


User-declared destructors have an implicit exception specification.

用户声明的析构函数具有隐式异常规范。

Example by me:

我的例子:

struct A {
  ~A() { throw "foo"; }
};

int main() { try { A a; } catch(...) { } }

This code calls terminate in C++0x, but does not in C++03. Because the implicit exception specification of A::~A in C++0x is noexcept(true).

此代码调用在c++ 0x中终止,但不使用c++ 03。因为c++ 0x中A::~A的隐式异常规范是noexcept(true)。


A valid C++ 2003 declaration containing export is ill-formed in C++0x.

包含出口的有效的c++ 2003声明在c++ 0x中是不正确的。


A valid C++ 2003 expression containing > followed immediately by another > may now be treated as closing two templates.

一个包含>的有效c++ 2003表达式,紧接着是另一个>,现在可以将其视为关闭两个模板。

In C++03, >> would always be the shift-operator token.

在c++ 03中,>>始终是移位操作符令牌。


Allow dependent calls of functions with internal linkage.

允许内部连接的函数的依赖调用。

Example by me:

我的例子:

static void f(int) { }
void f(long) { }

template<typename T>
void g(T t) { f(t); }

int main() { g(0); }

In C++03, this calls f(long), but in C++0x, this calls f(int). It should be noted that in both C++03 and C++0x, the following calls f(B) (the instantiation context still only considers extern linkage declarations).

在c++ 03中,它调用f(long),而在c++ 0x中,它调用f(int)。需要注意的是,在c++ 03和c++ 0x中,以下调用f(B)(实例化上下文仍然只考虑外部链接声明)。

struct B { };
struct A : B { };

template<typename T>
void g(T t) { f(t); }

static void f(A) { }
void f(B) { }

int main() { A a; g(a); }

The better matching f(A) is not taken, because it does not have external linkage.

由于f(A)没有外部连接,所以没有更好的匹配。


Library changes

Valid C++ 2003 code that uses any identifiers added to the C++ standard library of C++0x may fail to compile or produce different results in This International Standard.

使用添加到c++ c++ c++标准库的任何标识符的有效c++ 2003代码在这个国际标准中可能无法编译或产生不同的结果。


Valid C++ 2003 code that #includes headers with names of new C++0x standard library headers may be invalid in this International Standard.

在这个国际标准中,包含带有新c++ 0x标准库标头的#的有效c++ 2003代码可能无效。


Valid C++ 2003 code that has been compiled expecting swap to be in <algorithm> may have to instead include <utility>

有效的c++ 2003代码已经编译,期望交换在 <算法> 中,但可能必须包含


The global namespace posix is now reserved for standardization.

全局命名空间posix现在预留给标准化。


Valid C++ 2003 code that defines override, final, carries_dependency, or noreturn as macros is invalid in C++0x.

在c++ 0x中,定义重写、final、carries_dependency或noreturn为宏的有效c++ 2003代码无效。

#2


27  

The meaning of the auto keyword changed.

自动关键字的意思改变了。

#3


23  

Breaking change?

断改变?

Well, for one thing, if you used decltype, constexpr, nullptr, etc. as identifiers then you may be in trouble...

首先,如果您使用了decltype, constexpr, nullptr等作为标识符,那么您可能就有麻烦了……

#4


21  

Some core incompatibilities that are not covered by the incompatibilities section:

一些不兼容的核心不兼容部分:


C++0x treats the injected class name as a template, if the name is passed as an argument to a template template parameter, and as a type if it is passed to a template type parameter.

c++ 0x将注入的类名视为模板,如果将名称作为参数传递给模板模板参数,并将其作为类型传递给模板类型参数。

Valid C++03 code may behave differently if it relies on the injected class name to be always a type in these scenarios. Example code taken from my clang PR

如果有效的c++ 03代码依赖于在这些场景中注入的类名始终是类型,那么它的行为可能会有所不同。示例代码取自我的clang PR

template<template<typename> class X>
struct M { };

template<template<typename> class X>
void g(int = 0); // #1

template<typename T>
void g(long = 0); // #2

template<typename T>
struct A {
  void f() {
    g<A>(); /* is ambiguous in C++0x */
    g<A>(1); /* should choose #1 in C++0x */
  }
};

void h() {
  A<int> a;
  a.f();
}

In C++03, the code calls the second g both times.

在c++ 03中,代码两次都调用第二个g。


C++0x makes some names that were dependent in C++03 to be now non-dependent. And requires name lookup for non-dependent qualified names that refer to members of the current class template to be repeated at instantiation, and requires verification that these names lookup the same way as done at the template definition context.

c++ 0x使得一些名字在c++ 03中是不相关的。并且需要对引用当前类模板的成员的非相关限定名进行名称查找,并需要验证这些名称的查找方式是否与模板定义上下文相同。

Valid C++03 code that depends on the dominance rule may now not compile anymore because of this change.

基于支配规则的有效c++ 03代码现在可能不会再编译了,因为这个更改。

Example:

例子:

struct B { void f(); };

template<typename T>
struct A : virtual B { void f(); };

template<typename T>
struct C : virtual B, A<T> {
  void g() { this->f(); }
};

int main() { C<int> c; c.g(); }

This valid C++03 code that calls A<int>::f is not valid in C++0x, because name lookup when instantiating will find A<int>::f as opposed to B::f, causing a conflict with the at-definition lookup.

调用 :::f的有效c++ 03代码在c++ 0x中无效,因为实例化时的名称查找将发现 : f,而不是B::f,与at-definition查找产生冲突。

At this point, it is not clear whether that is a defect in the FDIS. The committee is aware of this and will evaluate the situation.

目前尚不清楚这是否是FDIS的缺陷。委员会认识到这一点,并将评估局势。


A using declaration where the last part is the same as the identifier in the last part of the qualifier in the qualified name denoting a base class, that using declaration now names the constructor, instead of members with that name.

一个使用声明,其中最后的部分与限定符的最后部分中的标识符在表示基类的限定名中的标识符相同,现在使用声明命名构造函数,而不是使用该名称的成员。

Example:

例子:

struct A { protected: int B; };
typedef A B;

struct C : B {
  // inheriting constructor, instead of bringing A::B into scope
  using B::B;
};

int main() { C c; c.B = 0; }

The above example code is well-formed in C++03, but ill-formed in C++0x, as A::B is still inaccessible in main.

上面的示例代码在c++ 03中很好地形成,但是在c++ 0x中是不正确的,因为在main中仍然无法访问B。

#5


13  

How is the introduction of explicit conversion operators a breaking change? The old version will still just be as "valid" as before.

如何引入显式转换操作符?旧版本仍将和以前一样“有效”。

Yes, the change from operator void*() const to explicit operator bool() const will be a breaking change, but only if it is used in a way that is wrong in and out of itself. Conforming code won't be broken.

是的,从操作符void*() const到显式操作符bool() const的更改将是一个彻底的更改,但只有在以错误的方式使用时才会如此。一致性代码不会被破坏。

Now, another breaking change is the banning of narrowing conversions during aggregate initialization:

现在,另一个重大的变化是在聚合初始化期间禁止收缩转换:

int a[] = { 1.0 }; // error

Edit: Just rememberer, std::identity<T> will be removed in C++0x (see the note). It's a convenience struct to make types dependent. Since the struct really doesn't do much, this should fix it:

编辑:记住,std::identity 将在c++ 0x中删除(请参阅注释)。它是一个方便的结构,使类型依赖。由于结构体真的没什么作用,这应该可以修复它:

template<class T>
struct identity{
  typedef T type;
};

#6


13  

Stream extraction failure is treated differently.

对流抽采失败的处理不同。

Example

#include <sstream>
#include <cassert>

int main()
{
   std::stringstream ss;
   ss << '!';

   int x = -1;

   assert(!(ss >> x)); // C++03 and C++11
   assert(x == -1);    // C++03
   assert(x == 0);     // C++11
}

Change proposal

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3246.html#23

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3246.html # 23

Standard reference

[C++03: 22.2.2.1.2/11]: The result of stage 2 processing can be one of

[C+ 03: 22.2.1.2 /11]:第二阶段处理的结果可以是

  • A sequence of chars has been accumulated in stage 2 that is converted (according to the rules of scanf) to a value of the type of val. This value is stored in val and ios_base::goodbit is stored in err.
  • 第2阶段积累了一系列chars,并将其转换为val类型的值(根据scanf的规则),该值存储在val中,ios_base: goodbit存储在err中。
  • The sequence of chars accumulated in stage 2 would have caused scanf to report an input failure. ios_base::failbit is assigned to err. [ed: Nothing is stored in val.]
  • 第2阶段积累的chars序列会导致scanf报告输入失败。ios_base: failbit被分配给err。[ed:没有任何东西被储存在val中。]

[C++11: 22.4.2.1.2/3]: [..] The numeric value to be stored can be one of:

[c++ 11:22.4.2.1.2/3]:[. .]所存储的数值可为:

  • zero, if the conversion function fails to convert the entire field. ios_base::failbit is assigned to err.
  • 零,如果转换函数不能转换整个字段。ios_base: failbit被分配给err。
  • the most positive representable value, if the field represents a value too large positive to be represented in val. ios_base::failbit is assigned to err.
  • 如果字段表示的值太大,无法在val. ios_base::failbit中表示,则为最积极的可表示值。
  • the most negative representable value or zero for an unsigned integer type, if the field represents a value too large negative to be represented in val. ios_base::failbit is assigned to err.
  • 对于无符号整数类型,如果字段表示一个值太大的负数,则表示在val. ios_base中,最负的可表示值或零值::failbit被指定为err。
  • the converted value, otherwise.
  • 转换后的值,否则。

The resultant numeric value is stored in val.

生成的数值存储在val中。

Implementations

  • GCC 4.8 correctly outputs for C++11:

    GCC 4.8 C+ 11的正确输出:

    Assertion `x == -1' failed

    断言' x == -1'失败

  • GCC 4.5-4.8 all output for C++03 the following, which would appear to be a bug:

    GCC 4.5-4.8 C+ 03的所有输出如下,这似乎是一个bug:

    Assertion `x == -1' failed

    断言' x == -1'失败

  • Visual C++ 2008 Express correctly outputs for C++03:

    Visual c++ 2008正确输出c++ 03:

    Assertion failed: x == 0

    断言失败:x = 0

  • Visual C++ 2012 Express incorrectly outputs for C++11, which would appear to be a status-of-implementation issue:

    Visual c++ 2012 Express错误地输出了c++ 11,这似乎是一个执行状态问题:

    Assertion failed: x == 0

    断言失败:x = 0

#7


8  

There are numerous changes to the containers library that allow more efficient code but silently break backwards compatibility for a few corner cases.

容器库中有许多更改,这些更改允许更有效的代码,但在一些情况下会悄悄地破坏向后兼容性。

Consider, for example, std::vector, default construction, C++0x, and breaking changes.

例如,考虑std::vector、默认结构、c++ 0x和中断更改。

#8


7  

There's been a lot of discussion of implicit move breaking backward compatibility

有很多关于隐式移动打破向后兼容性的讨论

(an older page with relevant discussion)

(有相关讨论的旧页)

If you read down into the comments, implicit move return is also a breaking change.

如果你往下读评论,隐式移动返回也是一个突破性的改变。

#9


6  

struct x {
   x(int) {}
};

void f(auto x = 3) { }

int main() {
   f();
}

C++03: valid.

c++ 03:有效。

C++0x: error: parameter declared 'auto'

c++ 0x:错误:参数声明为“auto”

#10


-1  

Language Features

  1. Uniform and general initialization using {}
  2. 使用{}进行统一和通用初始化
  3. auto
  4. 汽车
  5. Prevention of narrowing
  6. 预防缩小
  7. constexpr
  8. constexpr
  9. Range based for loop
  10. 基于范围的for循环
  11. nullptr
  12. nullptr
  13. enum class
  14. 枚举类
  15. static_assert
  16. static_assert
  17. std::initializer_list
  18. std::initializer_list
  19. Rvalue references (move semantics)
  20. 右值引用(语义)
  21. >>
  22. > >
  23. Lambdas
  24. λ
  25. Variadic templates
  26. 可变模板
  27. Type and template aliases
  28. 类型和模板的别名
  29. Unicode characters
  30. Unicode字符
  31. long long integer type
  32. 长长的整数类型
  33. alignas and alignof
  34. alignas和alignof
  35. decltype
  36. decltype
  37. Raw string literals
  38. 原始字符串
  39. Generalized POD
  40. 广义豆荚
  41. Generalized unions
  42. 广义的工会
  43. Local classes as template arguments
  44. 本地类作为模板参数
  45. Suffix return type syntax
  46. 后缀返回类型的语法
  47. [[carries_dependency]] and [[noreturn]]
  48. [[carries_dependency]]和[[noreturn]]
  49. noexcept specifier
  50. noexcept说明符
  51. noexcept operator.
  52. noexcept算子。
  53. C99 features:
    • extended integral types
    • 扩展积分类型
    • concatenation of narrow/wide string
    • 串联的窄或宽字符串
    • _ _ STDC_HOSTED _ _
    • _stdc_host __
    • _Pragma(X)
    • _Pragma(X)
    • vararg macros and empty macro arguments
    • vararg宏和空宏参数
  54. C99特性:扩展的整数类型连接窄/宽字符串_stdc_host ____pragma (X) vararg宏和空宏参数
  55. _ _ func _ _
  56. 是什么意思
  57. Inline namespaces
  58. 内联名称空间
  59. Delegating constructors
  60. 委托构造函数
  61. In-class member initializers
  62. 课堂成员初始化
  63. default and delete
  64. 违约和删除
  65. Explicit conversion operators
  66. 显式转换操作符
  67. User-defined literals
  68. 用户定义的文字
  69. Extern templates
  70. 外面的模板
  71. Default template arguments for function templates
  72. 函数模板的默认模板参数
  73. Inheriting constructors
  74. 继承的构造函数
  75. override and final
  76. 覆盖和最终
  77. Simpler and more general SFINAE rule
  78. 更简单和更一般的SFINAE规则
  79. Memory model
  80. 内存模型
  81. thread_local
  82. thread_local

Standard-Library Components

  1. initializer_list for containers
  2. initializer_list的容器
  3. Move semantics for containers
  4. 移动语义容器
  5. forward_list
  6. forward_list
  7. Hash containers
    • unordered_map
    • unordered_map
    • unordered_multimap
    • unordered_multimap
    • unordered_set
    • unordered_set
    • unordered_multiset
    • unordered_multiset
  8. 散列容器unordered_map unordered_multimap unordered_set unordered_set unordered_multiset
  9. Resource management pointers
    • unique_ptr
    • unique_ptr
    • shared_ptr
    • 要查看
    • weak_ptr
    • weak_ptr
  10. 资源管理指针unique_ptr shared_ptr weak_ptr
  11. Concurrency support
    • thread
    • 线程
    • mutexes
    • 互斥锁
    • locks
    • condition variables
    • 条件变量
  12. 并发性支持线程互斥锁条件变量
  13. Higher-level concurrency support
    • packaged_thread
    • packaged_thread
    • future
    • 未来
    • promise
    • 承诺
    • async
    • 异步
  14. 更高级别的并发支持packaged_thread未来承诺异步
  15. tuples
  16. 元组
  17. regex
  18. 正则表达式
  19. Random numbers
    • uniform_int_distribution
    • uniform_int_distribution
    • normal_distribution
    • normal_distribution
    • random_engine
    • random_engine
    • etc.
    • 等。
  20. 随机数均匀分布正态分布随机引擎等。
  21. Integer type names, such as int16_t , uint32_t , and int_fast64_t
  22. 整数类型名称,如int16_t、uint32_t和int_fast64_t
  23. array
  24. 数组
  25. Copying and rethrowing exceptions
  26. 复制并将异常
  27. system_error
  28. system_error
  29. emplace() operations for containers
  30. 安置()操作容器
  31. constexpr functions
  32. constexpr功能
  33. Systematic use of noexcept functions
  34. noexcept函数的系统使用
  35. function and bind
  36. 函数和绑定
  37. String to numeric value conversions
  38. 字符串到数值转换
  39. Scoped allocators
  40. 作用域的分配器
  41. Type traits
  42. 类型特征
  43. Time utilities: duration and time_point
  44. 时间工具:持续时间和时间点
  45. ratio
  46. quick_exit
  47. quick_exit
  48. More algorithms, such as move() , copy_if() , and is_sorted()
  49. 更多的算法,如move()、copy_if()和is_sort ()
  50. Garbage collection ABI
  51. 垃圾收集ABI
  52. atomics
  53. 原子

Deprecated Features

  1. Generation of the copy constructor and the copy assignment for a class with a destructor.
  2. 为具有析构函数的类生成复制构造函数和复制赋值。
  3. Assign a string literal to a char *.
  4. 将字符串字面量赋给char *。
  5. C++98 exception specification
    • unexcepted_handler
    • unexcepted_handler
    • set_unexpected
    • set_unexpected
    • get_unexpected
    • get_unexpected
    • unexpected
    • 意想不到的
  6. c++ 98异常规范unexcepted_handler set_unexpected get_unexpected unexpected unexpected
  7. Function objects and associated functions
  8. 函数对象和相关函数
  9. auto_ptr
  10. auto_ptr
  11. register
  12. 注册
  13. ++ on a bool
  14. bool + +
  15. export
  16. 出口
  17. C-style casts
  18. c风格的投