Skip to content

Fix compiler warnings#2381

Merged
jwillemsen merged 4 commits into
DOCGroup:masterfrom
jwillemsen:jwi-apgstreams
May 15, 2025
Merged

Fix compiler warnings#2381
jwillemsen merged 4 commits into
DOCGroup:masterfrom
jwillemsen:jwi-apgstreams

Conversation

@jwillemsen
Copy link
Copy Markdown
Member

@jwillemsen jwillemsen commented May 15, 2025

Summary by CodeRabbit

  • Refactor
    • Modernized class declarations by replacing empty constructors and destructors with compiler-generated defaults across multiple components.
    • Updated accessor methods to be const-correct in certain classes.
    • Initialized private member variables with default values in select classes.
    • Simplified the URL_Status class by removing an explicit copy constructor and adding defaulted copy operations.

    * ACE/examples/Web_Crawler/URL_Status.cpp:
    * ACE/examples/Web_Crawler/URL_Status.h:
    * ACE/examples/APG/Shared_Memory/Record.h:
    * ACE/examples/APG/Naming/EMail.h:
    * ACE/examples/APG/Signals/SigHandler.cpp:
    * ACE/examples/APG/Signals/SigHandlers.cpp:
    * ACE/examples/APG/Streams/CommandStream.h:
    * ACE/examples/APG/Streams/CommandTask.h:
    * ACE/examples/APG/Streams/Message.h:
    * ACE/examples/APG/ThreadPools/Futures.cpp:
    * ACE/examples/APG/ThreadPools/Task_ThreadPool.cpp:
    * ACE/examples/APG/ThreadPools/ThreadPool.cpp:
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2025

Walkthrough

This update modernizes several C++ classes by replacing explicitly defined empty constructors and destructors with compiler-generated defaults using = default;. Some accessor methods are marked as const, member variables are default-initialized, and copy operations for a status class are streamlined. No runtime logic or control flow is altered.

Changes

Files Change Summary
ACE/examples/APG/Naming/EMail.h
ACE/examples/APG/Streams/CommandStream.h
ACE/examples/APG/ThreadPools/Task_ThreadPool.cpp
Default constructors replaced with = default;
ACE/examples/APG/Shared_Memory/Record.h Default constructor/destructor replaced with = default;, accessors made const, member variables default-initialized
ACE/examples/APG/Signals/SigHandler.cpp
ACE/examples/APG/Signals/SigHandlers.cpp
ACE/examples/APG/Streams/Message.h
ACE/examples/APG/Streams/CommandTask.h
Destructors replaced with = default;
ACE/examples/APG/ThreadPools/Futures.cpp
ACE/examples/APG/ThreadPools/ThreadPool.cpp
Interface destructor replaced with = default;
ACE/examples/Web_Crawler/URL_Status.cpp Explicit copy constructor removed
ACE/examples/Web_Crawler/URL_Status.h Copy constructor explicitly defaulted; copy assignment operator defaulted and added

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Class
    Note over Class: Construction or Destruction
    User->>Class: Create instance
    Class-->>User: Instance created (default constructor)
    User->>Class: Destroy instance
    Class-->>User: Instance destroyed (default destructor)
Loading

Poem

In the warren of code, constructors hop—
Now defaulted, they quietly stop.
Destructors, too, take a restful nap,
As rabbits refactor with a gentle tap.
With copy and assign, the status is clear,
The code is refreshed—let’s give a cheer!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
ACE/examples/APG/ThreadPools/Task_ThreadPool.cpp (1)

97-106: 💡 Verification agent

🧩 Analysis chain

Consider how shutdown_ is set.

The class has a shutdown_ member that is checked in the done() method, but it's not clear how this member gets set to 1. Verify that there's a proper way to signal shutdown in the rest of the codebase.


🏁 Script executed:

#!/bin/bash
# Search for references to shutdown_ in the codebase
rg -A 5 -B 5 "shutdown_\s*=" ACE/examples/APG/ThreadPools/ --include="*.cpp" --include="*.h"

Length of output: 536


🏁 Script executed:

#!/bin/bash
# Search for any occurrences of shutdown_ in the ThreadPools example
rg -g '*.cpp' -g '*.h' -n 'shutdown_' ACE/examples/APG/ThreadPools/

# Locate the Manager class declaration
rg -g '*.h' -n 'class Manager' ACE/examples/APG/ThreadPools/

# Find Manager constructor implementation(s)
rg -g '*.cpp' -g '*.h' -n 'Manager::Manager' ACE/examples/APG/ThreadPools/

# Check for a Manager::shutdown method
rg -g '*.cpp' -g '*.h' -n 'Manager::shutdown' ACE/examples/APG/ThreadPools/

Length of output: 1627


Implement shutdown signaling in Task_ThreadPool’s Manager

The Manager in ACE/examples/APG/ThreadPools/Task_ThreadPool.cpp initializes shutdown_ to 0 but never sets it to 1, so done() will always return false and threads won’t exit. You need to add a way to signal shutdown and wake any waiting workers.

Attention needed in:

  • Task_ThreadPool.cpp, class Manager (around lines 60–99)
  • Manager::done() (lines 103–106)

Suggested fix:

 class Manager {
 public:
+  // Signal all workers to exit
+  void shutdown() {
+    shutdown_ = 1;
+    workers_cond_.notify_all();
+  }

   int done ();
 
 private:
   int shutdown_;
 };
 
 int Manager::done ()
 {
   return (shutdown_ == 1);
 }

And invoke mgr.shutdown() at the end of your task submission logic before joining threads.

🧹 Nitpick comments (4)
ACE/examples/APG/Streams/Message.h (2)

15-43: Consider marking accessor methods as const.

These accessor methods don't modify the object's state and should be marked as const to improve const-correctness:

-  RecordingDevice *recorder ()
+  RecordingDevice *recorder () const
   {
     return this->device_;
   }

-  MessageType *type ()
+  MessageType *type () const
   {
     return this->type_;
   }

-  CallerId *caller_id ()
+  CallerId *caller_id () const
   {
     return this->id_;
   }

-  ACE_FILE_Addr &addr ()
+  ACE_FILE_Addr &addr () const
   {
     return this->addr_;
   }

61-74: Mark query methods as const.

These methods are querying the state without modifying it and should be marked as const:

-  int is_text ()
+  int is_text () const
   {
     return this->type_->is_text ();
   }

-  int is_audio ()
+  int is_audio () const
   {
     return this->type_->is_audio ();
   }

-  int is_video ()
+  int is_video () const
   {
     return this->type_->is_video ();
   }
ACE/examples/Web_Crawler/URL_Status.h (1)

51-57: Consider initializing status_ in the class definition.

With C++11 and later, you can initialize class members at their point of declaration:

private:
-  STATUS_CODE status_;
+  STATUS_CODE status_ = STATUS_INSUFFICIENT_DATA;

This would simplify the constructor and make the default value more explicit.

ACE/examples/APG/Streams/CommandStream.h (1)

26-27: Consider using member initializer list for inherited.

The constructor initializes peer_ in the member initializer list but uses an empty initializer for inherited. Consider also initializing inherited in the member initializer list for consistency and potentially better performance:

-  CommandStream (ACE_SOCK_Stream *peer)
-    : inherited (), peer_(peer) { }
+  CommandStream (ACE_SOCK_Stream *peer)
+    : peer_(peer) { }

Since inherited() is invoking the default constructor, it can be omitted as base classes are default-initialized when not explicitly mentioned in the initializer list.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8bd289 and f31e4b6.

📒 Files selected for processing (12)
  • ACE/examples/APG/Naming/EMail.h (1 hunks)
  • ACE/examples/APG/Shared_Memory/Record.h (2 hunks)
  • ACE/examples/APG/Signals/SigHandler.cpp (1 hunks)
  • ACE/examples/APG/Signals/SigHandlers.cpp (1 hunks)
  • ACE/examples/APG/Streams/CommandStream.h (1 hunks)
  • ACE/examples/APG/Streams/CommandTask.h (1 hunks)
  • ACE/examples/APG/Streams/Message.h (1 hunks)
  • ACE/examples/APG/ThreadPools/Futures.cpp (1 hunks)
  • ACE/examples/APG/ThreadPools/Task_ThreadPool.cpp (1 hunks)
  • ACE/examples/APG/ThreadPools/ThreadPool.cpp (1 hunks)
  • ACE/examples/Web_Crawler/URL_Status.cpp (0 hunks)
  • ACE/examples/Web_Crawler/URL_Status.h (1 hunks)
💤 Files with no reviewable changes (1)
  • ACE/examples/Web_Crawler/URL_Status.cpp
🧰 Additional context used
🧬 Code Graph Analysis (2)
ACE/examples/APG/ThreadPools/Futures.cpp (1)
ACE/examples/APG/ThreadPools/ThreadPool.cpp (2)
  • IManager (20-20)
  • IManager (20-20)
ACE/examples/APG/ThreadPools/ThreadPool.cpp (1)
ACE/examples/APG/ThreadPools/Futures.cpp (2)
  • IManager (83-83)
  • IManager (83-83)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: macos-13-C++
  • GitHub Check: ubuntu-24.04 g++-10 CodeQL
  • GitHub Check: ubuntu-24.04 g++-10 wchar
  • GitHub Check: ubuntu-22.04 clang++-12
  • GitHub Check: ubuntu-24.04 clang++-14
  • GitHub Check: ubuntu-24.04 clang++-16
  • GitHub Check: ubuntu-24.04 g++-10 CORBA/e micro
  • GitHub Check: ubuntu-24.04 g++-10 ACE for TAO
  • GitHub Check: ubuntu-24.04 g++-10 CORBA/e compact
  • GitHub Check: ubuntu-22.04 g++-9
  • GitHub Check: ubuntu-24.04 g++-12
  • GitHub Check: ubuntu-22.04 g++-10
  • GitHub Check: ubuntu-24.04 g++-14
  • GitHub Check: ubuntu-24.04 g++-13
  • GitHub Check: ubuntu-22.04 clang++-13
  • GitHub Check: ubuntu-24.04 g++-11
  • GitHub Check: ubuntu-24.04 g++
  • GitHub Check: windows-2019 vs2019
🔇 Additional comments (13)
ACE/examples/APG/Streams/Message.h (1)

13-13: Good use of default destructor.

Modernizing the code by using = default; instead of an empty body is the right approach for the destructor.

ACE/examples/APG/ThreadPools/Task_ThreadPool.cpp (1)

14-14: Good use of default constructor.

Using = default; for the empty constructor is a proper modernization of the code.

ACE/examples/Web_Crawler/URL_Status.h (1)

48-49: Good use of default special member functions.

Explicitly defaulting the copy constructor and copy assignment operator is the right approach for modern C++ code. This makes the compiler's behavior explicit while eliminating the need for manual implementation.

ACE/examples/APG/Streams/CommandStream.h (1)

36-36: Good use of default constructor.

Using = default; for the empty constructor is a proper modernization of the code.

ACE/examples/APG/Streams/CommandTask.h (1)

16-16: Modernized destructor declaration is good.

The change from an explicitly defined empty destructor to a defaulted virtual destructor improves code readability and follows modern C++ practices while maintaining the same behavior.

ACE/examples/APG/ThreadPools/ThreadPool.cpp (1)

20-20: Good use of = default for interface destructor.

Modernizing the virtual destructor declaration to use = default is a good C++ practice. This matches the same pattern used in the related Futures.cpp file for consistency.

ACE/examples/APG/ThreadPools/Futures.cpp (1)

83-83: Good use of = default for interface destructor.

Using = default for the virtual destructor of the IManager interface class is a good modernization that maintains the same behavior while following contemporary C++ best practices.

ACE/examples/APG/Naming/EMail.h (1)

9-9: Good use of defaulted constructor.

Using = default for the constructor is a good C++ modernization practice. This maintains the same behavior while making the code more maintainable and easier to understand.

ACE/examples/APG/Signals/SigHandler.cpp (1)

13-13: Good modernization using default destructor

Replacing the explicitly defined empty destructor with = default; follows modern C++ best practices. This change clarifies intent and allows the compiler to generate the most efficient implementation.

ACE/examples/APG/Signals/SigHandlers.cpp (1)

12-12: Good use of defaulted destructor

Replacing the empty destructor implementation with = default; is a modern C++ best practice that improves code clarity.

ACE/examples/APG/Shared_Memory/Record.h (3)

16-17: Good modernization with defaulted special member functions

Replacing explicitly defined empty constructor and destructor with = default; follows modern C++ best practices. This makes the intent clearer and allows for potential compiler optimizations.


32-33: Correctly adding const qualifier to accessor methods

Adding the const qualifier to accessor methods that don't modify object state is good practice. This improves code safety and allows these methods to be called on const objects.


36-37: Good practice using member initializers

Adding default member initializers for the integer fields ensures they're zero-initialized even when using the default constructor. This prevents potential undefined behavior and aligns with modern C++ practices.

@jwillemsen jwillemsen merged commit faf8e40 into DOCGroup:master May 15, 2025
36 of 37 checks passed
@jwillemsen jwillemsen deleted the jwi-apgstreams branch May 15, 2025 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant