[RFC,v1,4/5] treewide: Use character literal instead of string in some cases
diff mbox series

Message ID 20260107193607.2168539-5-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • C++20 migration
Related show

Commit Message

Barnabás Pőcze Jan. 7, 2026, 7:36 p.m. UTC
Use character literals instead of single character long strings. The main
purpose of this change is to work around a GCC (libstdc++) bug that results
in `-Wrestrict` warnings at certain optimization levels in C++20.

Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/libcamera/base/log.cpp               | 12 ++++++------
 src/libcamera/media_pipeline.cpp         |  6 +++---
 src/libcamera/pipeline/simple/simple.cpp |  6 +++---
 3 files changed, 12 insertions(+), 12 deletions(-)

Comments

Laurent Pinchart Jan. 7, 2026, 8:33 p.m. UTC | #1
On Wed, Jan 07, 2026 at 08:36:06PM +0100, Barnabás Pőcze wrote:
> Use character literals instead of single character long strings. The main
> purpose of this change is to work around a GCC (libstdc++) bug that results
> in `-Wrestrict` warnings at certain optimization levels in C++20.

Has it been fixed in libstdc++ ? The bug report seems to indicate a
workaround has been merged in gcc 13.1. I'd list that in the commit
message.

> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  src/libcamera/base/log.cpp               | 12 ++++++------
>  src/libcamera/media_pipeline.cpp         |  6 +++---
>  src/libcamera/pipeline/simple/simple.cpp |  6 +++---
>  3 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index b28217750..946bdebf0 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -236,8 +236,8 @@ void LogOutput::write(const LogMessage &msg)
>  
>  	switch (target_) {
>  	case LoggingTargetSyslog:
> -		str = std::string(log_severity_name(severity)) + " "
> -		    + msg.category().name() + " " + msg.fileInfo() + " ";
> +		str = std::string(log_severity_name(severity)) + ' '
> +		    + msg.category().name() + ' ' + msg.fileInfo() + ' ';

We'll have to remember to use characters instead of strings, which isn't
very nice, but I can't think of a better workaround. CI should catch the
issues.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  		if (!msg.prefix().empty())
>  			str += msg.prefix() + ": ";
>  		str += msg.msg();
> @@ -245,11 +245,11 @@ void LogOutput::write(const LogMessage &msg)
>  		break;
>  	case LoggingTargetStream:
>  	case LoggingTargetFile:
> -		str = "[" + utils::time_point_to_string(msg.timestamp()) + "] ["
> +		str = '[' + utils::time_point_to_string(msg.timestamp()) + "] ["
>  		    + std::to_string(Thread::currentId()) + "] "
> -		    + severityColor + log_severity_name(severity) + " "
> -		    + categoryColor + msg.category().name() + " "
> -		    + fileColor + msg.fileInfo() + " ";
> +		    + severityColor + log_severity_name(severity) + ' '
> +		    + categoryColor + msg.category().name() + ' '
> +		    + fileColor + msg.fileInfo() + ' ';
>  		if (!msg.prefix().empty())
>  			str += prefixColor + msg.prefix() + ": ";
>  		str += resetColor + msg.msg();
> diff --git a/src/libcamera/media_pipeline.cpp b/src/libcamera/media_pipeline.cpp
> index 3c5517314..26c60c36b 100644
> --- a/src/libcamera/media_pipeline.cpp
> +++ b/src/libcamera/media_pipeline.cpp
> @@ -243,11 +243,11 @@ int MediaPipeline::init(MediaEntity *source, std::string_view sink)
>  			       [](const Entity &e) {
>  				       std::string s = "[";
>  				       if (e.sink)
> -					       s += std::to_string(e.sink->index()) + "|";
> +					       s += std::to_string(e.sink->index()) + '|';
>  				       s += e.entity->name();
>  				       if (e.source)
> -					       s += "|" + std::to_string(e.source->index());
> -				       s += "]";
> +					       s += '|' + std::to_string(e.source->index());
> +				       s += ']';
>  				       return s;
>  			       });
>  
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index b30b0a122..d37b76a48 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -578,11 +578,11 @@ SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
>  			       [](const Entity &e) {
>  				       std::string s = "[";
>  				       if (e.sink)
> -					       s += std::to_string(e.sink->index()) + "|";
> +					       s += std::to_string(e.sink->index()) + '|';
>  				       s += e.entity->name();
>  				       if (e.source)
> -					       s += "|" + std::to_string(e.source->index());
> -				       s += "]";
> +					       s += '|' + std::to_string(e.source->index());
> +				       s += ']';
>  				       return s;
>  			       });
>  }

Patch
diff mbox series

diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index b28217750..946bdebf0 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -236,8 +236,8 @@  void LogOutput::write(const LogMessage &msg)
 
 	switch (target_) {
 	case LoggingTargetSyslog:
-		str = std::string(log_severity_name(severity)) + " "
-		    + msg.category().name() + " " + msg.fileInfo() + " ";
+		str = std::string(log_severity_name(severity)) + ' '
+		    + msg.category().name() + ' ' + msg.fileInfo() + ' ';
 		if (!msg.prefix().empty())
 			str += msg.prefix() + ": ";
 		str += msg.msg();
@@ -245,11 +245,11 @@  void LogOutput::write(const LogMessage &msg)
 		break;
 	case LoggingTargetStream:
 	case LoggingTargetFile:
-		str = "[" + utils::time_point_to_string(msg.timestamp()) + "] ["
+		str = '[' + utils::time_point_to_string(msg.timestamp()) + "] ["
 		    + std::to_string(Thread::currentId()) + "] "
-		    + severityColor + log_severity_name(severity) + " "
-		    + categoryColor + msg.category().name() + " "
-		    + fileColor + msg.fileInfo() + " ";
+		    + severityColor + log_severity_name(severity) + ' '
+		    + categoryColor + msg.category().name() + ' '
+		    + fileColor + msg.fileInfo() + ' ';
 		if (!msg.prefix().empty())
 			str += prefixColor + msg.prefix() + ": ";
 		str += resetColor + msg.msg();
diff --git a/src/libcamera/media_pipeline.cpp b/src/libcamera/media_pipeline.cpp
index 3c5517314..26c60c36b 100644
--- a/src/libcamera/media_pipeline.cpp
+++ b/src/libcamera/media_pipeline.cpp
@@ -243,11 +243,11 @@  int MediaPipeline::init(MediaEntity *source, std::string_view sink)
 			       [](const Entity &e) {
 				       std::string s = "[";
 				       if (e.sink)
-					       s += std::to_string(e.sink->index()) + "|";
+					       s += std::to_string(e.sink->index()) + '|';
 				       s += e.entity->name();
 				       if (e.source)
-					       s += "|" + std::to_string(e.source->index());
-				       s += "]";
+					       s += '|' + std::to_string(e.source->index());
+				       s += ']';
 				       return s;
 			       });
 
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index b30b0a122..d37b76a48 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -578,11 +578,11 @@  SimpleCameraData::SimpleCameraData(SimplePipelineHandler *pipe,
 			       [](const Entity &e) {
 				       std::string s = "[";
 				       if (e.sink)
-					       s += std::to_string(e.sink->index()) + "|";
+					       s += std::to_string(e.sink->index()) + '|';
 				       s += e.entity->name();
 				       if (e.source)
-					       s += "|" + std::to_string(e.source->index());
-				       s += "]";
+					       s += '|' + std::to_string(e.source->index());
+				       s += ']';
 				       return s;
 			       });
 }