[libcamera-devel,1/2] meson.build: Switch to C++14

Message ID 20200114001531.27129-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit 9a61a134669c2240100fd1ccadaf974f86fe4655
Headers show
Series
  • [libcamera-devel,1/2] meson.build: Switch to C++14
Related show

Commit Message

Laurent Pinchart Jan. 14, 2020, 12:15 a.m. UTC
C++14 is a minor release that doesn't introduce major new concepts or
paradigms compared to C++11, but brings two useful changes for us:

- std::make_unique allows dropping our custom implementation in utils.
- Functions returning constexpr are not assumed to be const anymore,
  which is needed to create a standard-conformant span implementation.

All the g++ and clang++ versions we support and test (g++-5 onwards and
clang++6 onwards) support C++14. However, due to a defect in the
original C++14 specification, solved in N4387 ([1]), compilation would
fail on g++-5 due to the use of std::map::emplace() with a non-copyable
value type. It turns out we can easily fix it by switching to the
explicit piecewise emplace() overload.

There is thus really nothing holding back the switch. Let's do it, and
update the coding style accordingly.

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4387

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 Documentation/coding-style.rst | 23 +++++++++--------------
 meson.build                    |  2 +-
 src/ipa/rkisp1/rkisp1.cpp      |  4 +++-
 3 files changed, 13 insertions(+), 16 deletions(-)

Comments

Kieran Bingham Jan. 14, 2020, 2:11 a.m. UTC | #1
Hi Laurent,

On 14/01/2020 00:15, Laurent Pinchart wrote:
> C++14 is a minor release that doesn't introduce major new concepts or
> paradigms compared to C++11, but brings two useful changes for us:
> 
> - std::make_unique allows dropping our custom implementation in utils.
> - Functions returning constexpr are not assumed to be const anymore,
>   which is needed to create a standard-conformant span implementation.
> 
> All the g++ and clang++ versions we support and test (g++-5 onwards and
> clang++6 onwards) support C++14. However, due to a defect in the
> original C++14 specification, solved in N4387 ([1]), compilation would
> fail on g++-5 due to the use of std::map::emplace() with a non-copyable
> value type. It turns out we can easily fix it by switching to the
> explicit piecewise emplace() overload.

Eeep. That's a bit of a pain, but a short fix is helpful.

And we get to progress the defined standard.

> There is thus really nothing holding back the switch. Let's do it, and
> update the coding style accordingly.
> 

\o/

> [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4387
> 

All LGTM.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  Documentation/coding-style.rst | 23 +++++++++--------------
>  meson.build                    |  2 +-
>  src/ipa/rkisp1/rkisp1.cpp      |  4 +++-
>  3 files changed, 13 insertions(+), 16 deletions(-)
> 
> diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst
> index 9939c7b1e86d..bbc1f2fb18c6 100644
> --- a/Documentation/coding-style.rst
> +++ b/Documentation/coding-style.rst
> @@ -86,22 +86,17 @@ headers, and with double quotes for other libcamera headers.
>  C++ Specific Rules
>  ------------------
>  
> -The code shall be implemented in C++03, extended with the following
> -C++-11-specific features:
> -
> -* Initializer lists
> -* Type inference (auto and decltype)
> -  Type inference shall be used with caution, to avoid drifting towards an
> -  untyped language.
> -* Range-based for loop
> -* Lambda functions
> -* Explicit overrides and final
> -* Null pointer constant
> -* General-purpose smart pointers (std::unique_ptr), deprecating std::auto_ptr.
> +The code shall be implemented in C++14, with the following caveats:
> +
> +* Type inference (auto and decltype) shall be used with caution, to avoid
> +  drifting towards an untyped language.
> +* The explicit, override and final specifiers are to be used where applicable.
> +* General-purpose smart pointers (std::unique_ptr) deprecate std::auto_ptr.
>    Smart pointers, as well as shared pointers and weak pointers, shall not be
>    overused.
> -* Variadic class and function templates
> -* rvalue references, move constructor and move assignment
> +* Classes are encouraged to define move constructors and assignment operators
> +  where applicable, and generally make use of the features offered by rvalue
> +  references.
>  
>  Object Ownership
>  ~~~~~~~~~~~~~~~~
> diff --git a/meson.build b/meson.build
> index 634488589a46..37cf4d665f7b 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -4,7 +4,7 @@ project('libcamera', 'c', 'cpp',
>      default_options : [
>          'werror=true',
>          'warning_level=2',
> -        'cpp_std=c++11',
> +        'cpp_std=c++14',
>      ],
>      license : 'LGPL 2.1+')
>  
> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
> index 74b2922004be..a8dd1645d3e8 100644
> --- a/src/ipa/rkisp1/rkisp1.cpp
> +++ b/src/ipa/rkisp1/rkisp1.cpp
> @@ -104,7 +104,9 @@ void IPARkISP1::configure(const std::map<unsigned int, IPAStream> &streamConfig,
>  void IPARkISP1::mapBuffers(const std::vector<IPABuffer> &buffers)
>  {
>  	for (const IPABuffer &buffer : buffers) {
> -		auto elem = buffers_.emplace(buffer.id, buffer.planes);
> +		auto elem = buffers_.emplace(std::piecewise_construct,
> +					     std::forward_as_tuple(buffer.id),
> +					     std::forward_as_tuple(buffer.planes));
>  		const FrameBuffer &fb = elem.first->second;
>  
>  		/*
>
Niklas Söderlund Jan. 14, 2020, 2:21 p.m. UTC | #2
Hi Laurent,

Thanks for your work.

On 2020-01-14 02:15:30 +0200, Laurent Pinchart wrote:
> C++14 is a minor release that doesn't introduce major new concepts or
> paradigms compared to C++11, but brings two useful changes for us:
> 
> - std::make_unique allows dropping our custom implementation in utils.
> - Functions returning constexpr are not assumed to be const anymore,
>   which is needed to create a standard-conformant span implementation.
> 
> All the g++ and clang++ versions we support and test (g++-5 onwards and
> clang++6 onwards) support C++14. However, due to a defect in the
> original C++14 specification, solved in N4387 ([1]), compilation would
> fail on g++-5 due to the use of std::map::emplace() with a non-copyable
> value type. It turns out we can easily fix it by switching to the
> explicit piecewise emplace() overload.
> 
> There is thus really nothing holding back the switch. Let's do it, and
> update the coding style accordingly.
> 
> [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4387
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  Documentation/coding-style.rst | 23 +++++++++--------------
>  meson.build                    |  2 +-
>  src/ipa/rkisp1/rkisp1.cpp      |  4 +++-
>  3 files changed, 13 insertions(+), 16 deletions(-)
> 
> diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst
> index 9939c7b1e86d..bbc1f2fb18c6 100644
> --- a/Documentation/coding-style.rst
> +++ b/Documentation/coding-style.rst
> @@ -86,22 +86,17 @@ headers, and with double quotes for other libcamera headers.
>  C++ Specific Rules
>  ------------------
>  
> -The code shall be implemented in C++03, extended with the following
> -C++-11-specific features:
> -
> -* Initializer lists
> -* Type inference (auto and decltype)
> -  Type inference shall be used with caution, to avoid drifting towards an
> -  untyped language.
> -* Range-based for loop
> -* Lambda functions
> -* Explicit overrides and final
> -* Null pointer constant
> -* General-purpose smart pointers (std::unique_ptr), deprecating std::auto_ptr.
> +The code shall be implemented in C++14, with the following caveats:
> +
> +* Type inference (auto and decltype) shall be used with caution, to avoid
> +  drifting towards an untyped language.
> +* The explicit, override and final specifiers are to be used where applicable.
> +* General-purpose smart pointers (std::unique_ptr) deprecate std::auto_ptr.
>    Smart pointers, as well as shared pointers and weak pointers, shall not be
>    overused.
> -* Variadic class and function templates
> -* rvalue references, move constructor and move assignment
> +* Classes are encouraged to define move constructors and assignment operators
> +  where applicable, and generally make use of the features offered by rvalue
> +  references.
>  
>  Object Ownership
>  ~~~~~~~~~~~~~~~~
> diff --git a/meson.build b/meson.build
> index 634488589a46..37cf4d665f7b 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -4,7 +4,7 @@ project('libcamera', 'c', 'cpp',
>      default_options : [
>          'werror=true',
>          'warning_level=2',
> -        'cpp_std=c++11',
> +        'cpp_std=c++14',
>      ],
>      license : 'LGPL 2.1+')
>  
> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
> index 74b2922004be..a8dd1645d3e8 100644
> --- a/src/ipa/rkisp1/rkisp1.cpp
> +++ b/src/ipa/rkisp1/rkisp1.cpp
> @@ -104,7 +104,9 @@ void IPARkISP1::configure(const std::map<unsigned int, IPAStream> &streamConfig,
>  void IPARkISP1::mapBuffers(const std::vector<IPABuffer> &buffers)
>  {
>  	for (const IPABuffer &buffer : buffers) {
> -		auto elem = buffers_.emplace(buffer.id, buffer.planes);
> +		auto elem = buffers_.emplace(std::piecewise_construct,
> +					     std::forward_as_tuple(buffer.id),
> +					     std::forward_as_tuple(buffer.planes));
>  		const FrameBuffer &fb = elem.first->second;
>  
>  		/*
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst
index 9939c7b1e86d..bbc1f2fb18c6 100644
--- a/Documentation/coding-style.rst
+++ b/Documentation/coding-style.rst
@@ -86,22 +86,17 @@  headers, and with double quotes for other libcamera headers.
 C++ Specific Rules
 ------------------
 
-The code shall be implemented in C++03, extended with the following
-C++-11-specific features:
-
-* Initializer lists
-* Type inference (auto and decltype)
-  Type inference shall be used with caution, to avoid drifting towards an
-  untyped language.
-* Range-based for loop
-* Lambda functions
-* Explicit overrides and final
-* Null pointer constant
-* General-purpose smart pointers (std::unique_ptr), deprecating std::auto_ptr.
+The code shall be implemented in C++14, with the following caveats:
+
+* Type inference (auto and decltype) shall be used with caution, to avoid
+  drifting towards an untyped language.
+* The explicit, override and final specifiers are to be used where applicable.
+* General-purpose smart pointers (std::unique_ptr) deprecate std::auto_ptr.
   Smart pointers, as well as shared pointers and weak pointers, shall not be
   overused.
-* Variadic class and function templates
-* rvalue references, move constructor and move assignment
+* Classes are encouraged to define move constructors and assignment operators
+  where applicable, and generally make use of the features offered by rvalue
+  references.
 
 Object Ownership
 ~~~~~~~~~~~~~~~~
diff --git a/meson.build b/meson.build
index 634488589a46..37cf4d665f7b 100644
--- a/meson.build
+++ b/meson.build
@@ -4,7 +4,7 @@  project('libcamera', 'c', 'cpp',
     default_options : [
         'werror=true',
         'warning_level=2',
-        'cpp_std=c++11',
+        'cpp_std=c++14',
     ],
     license : 'LGPL 2.1+')
 
diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp
index 74b2922004be..a8dd1645d3e8 100644
--- a/src/ipa/rkisp1/rkisp1.cpp
+++ b/src/ipa/rkisp1/rkisp1.cpp
@@ -104,7 +104,9 @@  void IPARkISP1::configure(const std::map<unsigned int, IPAStream> &streamConfig,
 void IPARkISP1::mapBuffers(const std::vector<IPABuffer> &buffers)
 {
 	for (const IPABuffer &buffer : buffers) {
-		auto elem = buffers_.emplace(buffer.id, buffer.planes);
+		auto elem = buffers_.emplace(std::piecewise_construct,
+					     std::forward_as_tuple(buffer.id),
+					     std::forward_as_tuple(buffer.planes));
 		const FrameBuffer &fb = elem.first->second;
 
 		/*