BewareMyPower commented on code in PR #15928:
URL: https://github.com/apache/pulsar/pull/15928#discussion_r889707814


##########
pulsar-client-cpp/lib/auth/AuthOauth2.cc:
##########
@@ -143,6 +143,18 @@ ClientCredentialFlow::ClientCredentialFlow(ParamMap& 
params)
       audience_(params["audience"]),
       scope_(params["scope"]) {}
 
+const std::string ClientCredentialFlow::getWellKnownOpenIdConfigurationUrl() {

Review Comment:
   In C++, returning a const value is meaningless, for example, given the 
following function that returns a const `std::string`
   
   ```c++
   const std::string f() { return "hello"; }
   ```
   
   Then we have:
   
   ```c++
   // It's an assignment by value, i.e. deep copy in Java, so s1 is non-const
   auto s1 = f();
   s1.append("world"); // OK because the type of s1 is non-const
   // s2 is a const reference, but it's dangerous in C++ because f() returns a 
temporary variable.
   auto& s2 = f();
   // s2.append("world"); // Failed because s2 references to a const object
   ```
   
   It's dangerous to use `s2` in the above example because it references a 
temporary variable. See following example:
   
   ```c++
   #include <iostream>
   using namespace std;
   
   const std::string f() { return "hello"; }
   
   const std::string& g() {
       auto& s = f();
       return s;
   }
   
   int main(int argc, char* argv[]) {
       auto& s = g();
       cout << s << endl;
       return 0;
   }
   ```
   
   When you compile this program, you can see the warning from the Clang output:
   
   ```
   1.cc:8:12: warning: returning reference to local temporary object 
[-Wreturn-stack-address]
       return s;
              ^
   1.cc:7:11: note: binding reference variable 's' here
       auto& s = f();
   ```
   
   And the output is undefined.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to