mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
68
build/clang-plugin/tests/TestAssertWithAssignment.cpp
Normal file
68
build/clang-plugin/tests/TestAssertWithAssignment.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#include "mozilla/MacroArgs.h"
|
||||
|
||||
static __attribute__((always_inline)) bool MOZ_AssertAssignmentTest(bool expr) {
|
||||
return expr;
|
||||
}
|
||||
|
||||
#define MOZ_UNLIKELY(x) (__builtin_expect(!!(x), 0))
|
||||
#define MOZ_CRASH() do { } while(0)
|
||||
#define MOZ_CHECK_ASSERT_ASSIGNMENT(expr) MOZ_AssertAssignmentTest(!!(expr))
|
||||
|
||||
#define MOZ_ASSERT_HELPER1(expr) \
|
||||
do { \
|
||||
if (MOZ_UNLIKELY(!MOZ_CHECK_ASSERT_ASSIGNMENT(expr))) { \
|
||||
MOZ_CRASH();\
|
||||
} \
|
||||
} while(0) \
|
||||
|
||||
/* Now the two-argument form. */
|
||||
#define MOZ_ASSERT_HELPER2(expr, explain) \
|
||||
do { \
|
||||
if (MOZ_UNLIKELY(!MOZ_CHECK_ASSERT_ASSIGNMENT(expr))) { \
|
||||
MOZ_CRASH();\
|
||||
} \
|
||||
} while(0) \
|
||||
|
||||
#define MOZ_RELEASE_ASSERT_GLUE(a, b) a b
|
||||
#define MOZ_RELEASE_ASSERT(...) \
|
||||
MOZ_RELEASE_ASSERT_GLUE( \
|
||||
MOZ_PASTE_PREFIX_AND_ARG_COUNT(MOZ_ASSERT_HELPER, __VA_ARGS__), \
|
||||
(__VA_ARGS__))
|
||||
|
||||
#define MOZ_ASSERT(...) MOZ_RELEASE_ASSERT(__VA_ARGS__)
|
||||
|
||||
void FunctionTest(int p) {
|
||||
MOZ_ASSERT(p = 1); // expected-error {{Forbidden assignment in assert expression}}
|
||||
}
|
||||
|
||||
void FunctionTest2(int p) {
|
||||
MOZ_ASSERT(((p = 1))); // expected-error {{Forbidden assignment in assert expression}}
|
||||
}
|
||||
|
||||
void FunctionTest3(int p) {
|
||||
MOZ_ASSERT(p != 3);
|
||||
}
|
||||
|
||||
class TestOverloading {
|
||||
int value;
|
||||
public:
|
||||
explicit TestOverloading(int _val) : value(_val) {}
|
||||
// different operators
|
||||
explicit operator bool() const { return true; }
|
||||
TestOverloading& operator=(const int _val) { value = _val; return *this; }
|
||||
|
||||
int& GetInt() {return value;}
|
||||
};
|
||||
|
||||
void TestOverloadingFunc() {
|
||||
TestOverloading p(2);
|
||||
int f;
|
||||
|
||||
MOZ_ASSERT(p);
|
||||
MOZ_ASSERT(p = 3); // expected-error {{Forbidden assignment in assert expression}}
|
||||
MOZ_ASSERT(p, "p is not valid");
|
||||
MOZ_ASSERT(p = 3, "p different than 3"); // expected-error {{Forbidden assignment in assert expression}}
|
||||
MOZ_ASSERT(p.GetInt() = 2); // expected-error {{Forbidden assignment in assert expression}}
|
||||
MOZ_ASSERT(p.GetInt() == 2);
|
||||
MOZ_ASSERT(p.GetInt() == 2, f = 3);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue