[llvm-bugs] [Bug 38657] Test using strcmp fails after r339410

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 21 06:07:30 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38657

Douglas Yung <douglas_yung at playstation.sony.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #5 from Douglas Yung <douglas_yung at playstation.sony.com> ---
Sorry, when cutting down the test, I think I may have invalidated it. Here is
the original test case:

/* test.cpp */
#include <string.h>
#include <assert.h>

struct String {
  char  content[100];
  String (const String& a) {
    strcpy(content, a.content);
  }
  String (const char* a) {
    strcpy(content, a);
  }
  operator const char* () const {
    return content;
  }
};

String operator+ (const String& a, const String& b) {
  String res("Error!");
  if (strcmp(a, "one") == 0 && strcmp(b, "one") == 0) {
    res = String("two");
  }
  if (strcmp(a, "one") == 0 && strcmp(b, "two") == 0) {
    res = String("three");
  }
  return res;
}

int main()
{
    String res1 = String("one") + String("two");
    assert(strcmp(res1, "three") == 0);
    char const* str1 = String("one") + String("two");
    assert(strcmp(str1, "three") == 0);

    String res2 = String("one") + "one";
    assert(strcmp(res2, "two") == 0);
    char const* str2 = String("one") + "one";
    assert(strcmp(str2, "two") == 0);

    String res3 = "one" + String("two");
    assert(strcmp(res3, "three") == 0);
    char const* str3 = "one" + String("two");
    assert(strcmp(str3, "three") == 0);

    return 0;
}

On my machine with gcc 5.5 and -O2, the code does NOT fail, while with clang
r399410 it does.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180821/390c2c33/attachment.html>


More information about the llvm-bugs mailing list