반응형

modernize-pass-by-value

With move semantics added to the language and the standard library updated with move constructors added for many types it is now interesting to take an argument directly by value, instead of by const-reference, and then copy. This check allows the compiler to take care of choosing the best way to construct the copy.

언어에 이동 의미론(move semantics)이 추가되고
많은 타입에 대한 이동 생성자(move constructors)가 추가된 표준 라이브러리가 업데이트되면서
이제는 const-reference 대신, 직접 값으로 인자를 받고 복사하는 것이 흥미롭다.
이 검사를 통해 컴파일러는 복사본을 생성하는 가장 좋은 방법을 선택할 수 있습니다.

 

The transformation is usually beneficial when the calling code passes an rvalue and assumes the move construction is a cheap operation. This short example illustrates how the construction of the value happens:

이 변환은 보통, 호출 코드가
rvalue을 전달(passes an rvalue)하고 이동 생성(move construction)이 저렴한 작업이라고 추정할 때 유용합니다.
이 짧은 예는 값의 생성이 어떻게 이루어지는지 보여줍니다.
=> 해설 : 매개변수 s가 pass by value 지만, lvalue와 rvalue에 따라 copy, move 를 선택한다

void foo(std::string s);
std::string get_str();

void f(const std::string &str) {
  foo(str);       // lvalue  -> copy construction
  foo(get_str()); // prvalue -> move construction
}

 

Note
Currently, only constructors are transformed to make use of pass-by-value. Contributions that handle other situations are welcome!

주의
현재 생성자만 pass-by-value를 사용하도록 변환됩니다. 다른 상황을 처리하는 기여도 환영합니다!

 

 

Pass-by-value in constructors

Replaces the uses of const-references constructor parameters that are copied into class fields. The parameter is then moved with std::move().
Since std::move() is a library function declared in <utility> it may be necessary to add this include. The check will add the include directive when necessary.

클래스 필드로 복사되는 const-reference 생성자 매개변수의 사용을 교체합니다.
이 매개변수는 std::move를 통해 이동됩니다.
std::move()는 <utility>에 선언된 라이브러리 함수이므로 이 include문의 추가가 필요할 수도 있습니다.
이 검사는 필요한 경우 포함문을 추가합니다.

 #include <string>

 class Foo {
 public:
-  Foo(const std::string &Copied, const std::string &ReadOnly)
-    : Copied(Copied), ReadOnly(ReadOnly)
+  Foo(std::string Copied, const std::string &ReadOnly)
+    : Copied(std::move(Copied)), ReadOnly(ReadOnly)
   {}

 private:
   std::string Copied;
   const std::string &ReadOnly;
 };

 std::string get_cwd();

 void f(const std::string &Path) {
   // The parameter corresponding to 'get_cwd()' is move-constructed. By
   // using pass-by-value in the Foo constructor we managed to avoid a
   // copy-construction.
   Foo foo(get_cwd(), Path);
 }
If the parameter is used more than once no transformation is performed since moved objects have an undefined state. It means the following code will be left untouched:

매개변수를 한번 이상 사용하지 않으면 변환이 수행되지 않는다,
왜냐하면 이동된 객체의 상태가 정의되지 않았기 때문이다.
다음 코드가 변경되지 않는 상태로 유지됨을 의미한다.

 

#include <string>

void pass(const std::string &S);

struct Foo {
  Foo(const std::string &S) : Str(S) {
    pass(S);
  }

  std::string Str;
};

 

Known limitations

A situation where the generated code can be wrong is when the object referenced is modified before the assignment in the init-list through a “hidden” reference.

생성된 코드가 틀릴 수 있는 상황은
init-list로 초기화 되기 전에 숨겨진 참조에 의해 참조된 객체가 변경되는 경우이다.

 

Example:

 std::string s("foo");

 struct Base {
   Base() {
     s = "bar";
   }
 };

 struct Derived : Base {
-  Derived(const std::string &S) : Field(S)
+  Derived(std::string S) : Field(std::move(S))
   { }

   std::string Field;
 };

 void f() {
-  Derived d(s); // d.Field holds "bar"
+  Derived d(s); // d.Field holds "foo"
 }

 

Not about delayed template parsing

When delayed template parsing is enabled, constructors part of templated contexts; templated constructors, constructors in class templates, constructors of inner classes of template classes, etc., are not transformed. Delayed template parsing is enabled by default on Windows as a Microsoft extension: Clang Compiler User’s Manual - Microsoft extensions.

Delayed template parsing can be enabled using the -fdelayed-template-parsing flag and disabled using -fno-delayed-template-parsing.

Example:

  template <typename T> class C {
    std::string S;

  public:
=  // using -fdelayed-template-parsing (default on Windows)
=  C(const std::string &S) : S(S) {}

+  // using -fno-delayed-template-parsing (default on non-Windows systems)
+  C(std::string S) : S(std::move(S)) {}
  };

See also

For more information about the pass-by-value idiom, read: Want Speed? Pass by Value.

Options

IncludeStyle

A string specifying which include-style is used, llvm or google. Default is llvm.

ValuesOnly

When true, the check only warns about copied parameters that are already passed by value. Default is false.


출처

함께 보면 좋은 글

반응형
반응형

오늘은 VMware 로 듀얼 모니터 사용하는 방법을 소개하려고 합니다.

 

VMware 를 사용하고 계신가요?

 

VMware 는 VM웨어 회사에서 만든 가상화 솔루션입니다.

 

간단하게 설명하면 내 Windows 운영체제 안에 Windows 를 또 실행 시킬 수 있는 환경을 제공하는 프로그램입니다.

 

예전에는 개발자들이 주로 사용했지만, 최근엔 다양한 직군의 업무 환경에서도 VMware를 포함한 가상화 솔루션들을 많이 들 사용하는 것 같습니다.

 

듀얼 모니터 혹은 그 이상의 다중 모니터를 사용하시는 분이라면

VMware 화면을 다른 모니터로 확장할 수 있습니다.

 

제가 사용하는 버전은 VMware Workstation 16 Pro 인데요.

VMware 로 듀얼 모니터 사용하는 방법은 간단합니다.

 

 

1. 먼저 [View] > [Full Screen] 을 클릭하면 전체화면이 됩니다

 

 

 

2. 그 다음 다시 [View] 를 클릭하면 [Cycle Multiple Monitors] 메뉴가 보입니다. 클릭해주세요.

 

 

그럼 다음과 같이 VMware 화면이 다른 다른 모니터로 확장됩니다.

 

VMware의 가상화된 환경을 마치 실PC처럼 듀얼모니터로 확장해서 편리하게 사용하실 수 있습니다.

반응형
반응형

아래 처럼 조건문에서 입력과 조건체크를 함께 진행하는 경우 유용할 수 있습니다.

 if (numeric_read(str, &err), !err)

numeric_read함수는 호출만 되고, !err 조건만 판단하게 됩니다.

 

 

콤마 연산자에 대한 자세한 설명은 아래 링크들을 참고해주세요

https://dad-rock.tistory.com/117

https://www.inflearn.com/questions/137837

https://stackoverflow.com/questions/16475032/comma-operator-in-if-condition

반응형
반응형

윈도우에서 파일에 디지털 서명 후 인증서 체인이 올바르지 않은 문제가 발생했는데요.

 

인증서 체인이 올바르지 않은 경우의 원인은 다양할 수 있습니다.

 

이번에 공유하고자 이슈는 중간 인증서(intermidiate certificate)누락 이슈입니다.

 

 

정상적인 상황이라면 아래와 같이 인증 경로에 인증서 체인이 올바르게 나타나고

올바른 인증서라는 메세지가 보여야합니다.

 

 

이슈 재현

  • 오프라인 상태의 PC A에서 MyFile.exe에 SignTool로 서명을 수행
  • 오프라인 상태이므로 중간 인증서의 자동 다운로드가 불가한 상태
  • (오프라인 상태보다 중간 인증서가 없는게 중요)
  • PC B에서 MyFile.exe > [속성] > [디지털 서명] > [자세히] > [인증서 보기] > [인증 경로] 를 보면
    • PC B가 오프라인이라면 인증서 체인이 없는 것을 확인할 수 있습니다.
    • PC B가 온라인이며, 중간 인증서 다운로드에 문제가 없다면 디지털 서명이 정상으로 나옵니다

 

이슈 원인

  • 원인은 이슈 재현에 이미 설명이 나와있는 것처럼 중간 인증서 다운로드에 실패했기 때문입니다.
  • 만약 PC A 에서라도 중간 인증서가 올바르게 존재하는 상태에서 서명이 진행되었다면 문제가 되지 않았을 겁니다.

 

 

이슈 점검 및 해결

  • [속성] > [디지털 서명] > [자세히] > [인증서 보기] > [자세히] 탭을 보시면 [기관 정보 엑세스] 필드를 볼 수 있습니다.
    • 여기서 보이는 URL값이 발급 기관 인증서 즉, 중간 인증서를 받을 수 있는 URL입니다.
    • 서명을 수행하는 PC에서 해당 URL로 인증서를 수동으로 다운로드 해보고 문제가 없는지 확인해볼 수 있겠네요.
    • 인증서 다운로드에 문제가 있다면 수동으로 인증서를 설치해줍니다.

이슈 개선

  • 서명 과정에서 SingTool을 사용한 verify 명령어를 통해 서명을 체크하는 로직을 추가해 문제 상황을 확인할 수 있습니다.
    (cf. CI 빌드 시스템에서 오류를 인식할 수 있도록 )

 

 

정리해보면, 디지털 서명을 수행하는 PC에 인증서 체인의 인증서들이 모두 존재하도록 하는것게 가장 안전한 방법인것 같습니다.

반응형

+ Recent posts